<tfoot id='Cpwyn'></tfoot>
      <i id='Cpwyn'><tr id='Cpwyn'><dt id='Cpwyn'><q id='Cpwyn'><span id='Cpwyn'><b id='Cpwyn'><form id='Cpwyn'><ins id='Cpwyn'></ins><ul id='Cpwyn'></ul><sub id='Cpwyn'></sub></form><legend id='Cpwyn'></legend><bdo id='Cpwyn'><pre id='Cpwyn'><center id='Cpwyn'></center></pre></bdo></b><th id='Cpwyn'></th></span></q></dt></tr></i><div id='Cpwyn'><tfoot id='Cpwyn'></tfoot><dl id='Cpwyn'><fieldset id='Cpwyn'></fieldset></dl></div>

      <small id='Cpwyn'></small><noframes id='Cpwyn'>

        • <bdo id='Cpwyn'></bdo><ul id='Cpwyn'></ul>
      1. <legend id='Cpwyn'><style id='Cpwyn'><dir id='Cpwyn'><q id='Cpwyn'></q></dir></style></legend>

        如何使用日期范围填充表格?

        时间:2023-08-18

          <tfoot id='37oIU'></tfoot>

              <bdo id='37oIU'></bdo><ul id='37oIU'></ul>
                <tbody id='37oIU'></tbody>
              <i id='37oIU'><tr id='37oIU'><dt id='37oIU'><q id='37oIU'><span id='37oIU'><b id='37oIU'><form id='37oIU'><ins id='37oIU'></ins><ul id='37oIU'></ul><sub id='37oIU'></sub></form><legend id='37oIU'></legend><bdo id='37oIU'><pre id='37oIU'><center id='37oIU'></center></pre></bdo></b><th id='37oIU'></th></span></q></dt></tr></i><div id='37oIU'><tfoot id='37oIU'></tfoot><dl id='37oIU'><fieldset id='37oIU'></fieldset></dl></div>

              <small id='37oIU'></small><noframes id='37oIU'>

              1. <legend id='37oIU'><style id='37oIU'><dir id='37oIU'><q id='37oIU'></q></dir></style></legend>

                  本文介绍了如何使用日期范围填充表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要一个 MySQL 表来保存 2011-01-01 和 2011-12-31 之间的所有日期.我创建了一个列名为_date"的表,键入 DATE.

                  I need a MySQL table to hold ALL DATES between 2011-01-01 and 2011-12-31. I have created a table with one column names "_date", type DATE.

                  我可以使用什么查询在表格中填充所有所需的日期(而不必手动输入)?

                  With what query can I populate the table with all the desired dates (instead of having to enter them by hand)?

                  推荐答案

                  试试这个:

                  DROP PROCEDURE IF EXISTS filldates;
                  DELIMITER |
                  CREATE PROCEDURE filldates(dateStart DATE, dateEnd DATE)
                  BEGIN
                    WHILE dateStart <= dateEnd DO
                      INSERT INTO tablename (_date) VALUES (dateStart);
                      SET dateStart = date_add(dateStart, INTERVAL 1 DAY);
                    END WHILE;
                  END;
                  |
                  DELIMITER ;
                  CALL filldates('2011-01-01','2011-12-31');
                  

                  这是使用它的 SQL Fiddle:http://sqlfiddle.com/#!2/65d13/1

                  Here's the SQL Fiddle to play with it: http://sqlfiddle.com/#!2/65d13/1

                  按照 安德鲁·福克斯.

                  CREATE PROCEDURE filldates(dateStart DATE, dateEnd DATE)
                  
                  BEGIN
                  
                  DECLARE adate date;
                  
                      WHILE dateStart <= dateEnd DO
                  
                          SET adate = (SELECT mydate FROM MyDates WHERE mydate = dateStart);
                  
                          IF adate IS NULL THEN BEGIN
                  
                              INSERT INTO MyDates (mydate) VALUES (dateStart);
                  
                          END; END IF;
                  
                          SET dateStart = date_add(dateStart, INTERVAL 1 DAY);
                  
                      END WHILE;
                  
                  END;//
                  

                  这里是使用它的 SQL Fiddle:http://sqlfiddle.com/#!2/66f86/1

                  Here's the SQL Fiddle to play with it: http://sqlfiddle.com/#!2/66f86/1

                  这篇关于如何使用日期范围填充表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用某些前缀使 MySQL 表主键自动递增 下一篇:SELECT 列表不在 GROUP BY 子句中并且包含非聚合列

                  相关文章

                  最新文章

                  1. <tfoot id='AiKgC'></tfoot>

                      <bdo id='AiKgC'></bdo><ul id='AiKgC'></ul>

                      <legend id='AiKgC'><style id='AiKgC'><dir id='AiKgC'><q id='AiKgC'></q></dir></style></legend>

                      <i id='AiKgC'><tr id='AiKgC'><dt id='AiKgC'><q id='AiKgC'><span id='AiKgC'><b id='AiKgC'><form id='AiKgC'><ins id='AiKgC'></ins><ul id='AiKgC'></ul><sub id='AiKgC'></sub></form><legend id='AiKgC'></legend><bdo id='AiKgC'><pre id='AiKgC'><center id='AiKgC'></center></pre></bdo></b><th id='AiKgC'></th></span></q></dt></tr></i><div id='AiKgC'><tfoot id='AiKgC'></tfoot><dl id='AiKgC'><fieldset id='AiKgC'></fieldset></dl></div>

                      <small id='AiKgC'></small><noframes id='AiKgC'>