zoukankan      html  css  js  c++  java
  • mysql获取给定时间段内的所有日期列表

    DELIMITER $$
    DROP PROCEDURE IF EXISTS create_calendar $$
    CREATE PROCEDURE create_calendar (s_date DATE, e_date DATE)
    BEGIN
      -- 生成一个日历表
        SET @createSql = 'CREATE TABLE IF NOT EXISTS calendar_custom (
                          `date` date NOT NULL,
                          UNIQUE KEY `unique_date` (`date`) USING BTREE
                          )ENGINE=InnoDB DEFAULT CHARSET=utf8';
        prepare stmt from @createSql;
        execute stmt;
        WHILE s_date <= e_date DO
            INSERT IGNORE INTO calendar_custom VALUES (DATE(s_date)) ;
            SET s_date = s_date + INTERVAL 1 DAY ;
        END WHILE ;
    END$$
    DELIMITER ;
    
    -- 生成数据到calendar_custom表2009-01-01~2029-01-01之间的所有日期数据
    CALL create_calendar ('2009-01-01', '2029-01-01');
    

      

    DELIMITER $$
    DROP PROCEDURE IF EXISTS create_calendar $$
    CREATE PROCEDURE create_calendar (s_date DATE, e_date DATE)
    BEGIN
      
      -- 生成一个日历表
        SET @createSql = 'truncate TABLE  calendar_custom';
        prepare stmt from @createSql;
        execute stmt;
      
        WHILE s_date <= e_date DO
            INSERT IGNORE INTO calendar_custom VALUES (DATE(s_date)) ;
            SET s_date = s_date + INTERVAL 1 DAY ;
        END WHILE ;
      
    END$$
    DELIMITER ;
     
    -- 生成数据到calendar_custom表2009-01-01~2029-01-01之间的所有日期数据
     CALL create_calendar ('2009-01-02', '2009-01-07');
    

      

     
  • 相关阅读:
    希尔排序(Shell Sorting)
    插入排序(Insertion Sorting)
    选择排序(Select Sorting)
    冒泡排序(Bubble Sorting)
    排序算法(Sort Algorithm)
    递归(Recursion)
    包的导入
    Base64编码
    python各种模块,迭代器,生成器
    CF821 B. Okabe and Banana Trees 简单数学
  • 原文地址:https://www.cnblogs.com/liangmm/p/12938857.html
Copyright © 2011-2022 走看看