思路:为时间段内的数据进行编序号,然后计算好相隔时间,拿到id作为搜索条件 SELECT * FROM ( SELECT (@i:=@i+1) as i, id, data_send_time FROM jl_pims_machine_time mt,(select @i:=0) as it where mt.company_id = 1001 AND mt.machine_id = 1 order by mt.id desc) tmpWHERE i IN (1,3,5)…
创建表dim_date: create table `dim_date` ( `year` int (20), `month` int (20), `day` int (20), `week` int (11), `quarter` int (20), `date_id` date ); mysql中创建存储过程createDates 插入每一天的日期(我是从2015-10-01开始后的1000天,大概到2018年) DELIMITER $$ CREATE PROCEDURE `view`.`c…
如何实现没有的时间段中使用0来填充?? if object_id('[A]') is not null drop table [A] go create table [A]([日期] datetime,[金额] int) insert [A] select * from [A] union all union all union all declare @stdate smalldatetime, @eddate smalldatetime select @stdate=min([日期]), @…
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…