当天24小时数据
SELECT DATE_FORMAT( DATE_SUB( DATE_FORMAT( NOW(),‘%Y-%m-%d‘),INTERVAL ( -(@i:=@i+1) ) HOUR ) ,‘%Y-%m-%d %H‘) AS ‘time‘ FROM ( SELECT a FROM (SELECT ‘1‘ AS a UNION SELECT ‘2‘ UNION SELECT ‘3‘ UNION SELECT ‘4‘ ) AS a JOIN ( SELECT ‘1‘ UNION SELECT ‘2‘ UNION SELECT ‘3‘ UNION SELECT ‘4‘ UNION SELECT ‘5‘ UNION SELECT ‘6‘ ) AS b ON 1 ) AS b ,(SELECT @i:=-1) AS i
当前时间向前偏移24小时
SELECT DATE_FORMAT( DATE_SUB( DATE_FORMAT( NOW(),‘%Y-%m-%d %H‘),INTERVAL ( (@i:=@i+1) ) HOUR ) ,‘%H‘) AS ‘time‘ FROM ( SELECT a FROM (SELECT ‘1‘ AS a UNION SELECT ‘2‘ UNION SELECT ‘3‘ UNION SELECT ‘4‘ ) AS a JOIN ( SELECT ‘1‘ UNION SELECT ‘2‘ UNION SELECT ‘3‘ UNION SELECT ‘4‘ UNION SELECT ‘5‘ UNION SELECT ‘6‘ ) AS b ON 1 ) AS b ,(SELECT @i:=-1) AS i
当前时间向前偏移7天
SELECT DATE_FORMAT( DATE_SUB( DATE_FORMAT( NOW(),‘%Y-%m-%d‘),INTERVAL ( (@i:=@i+1) ) DAY ) ,‘%d‘) AS ‘time‘ FROM ( SELECT a FROM (SELECT ‘1‘ AS a UNION SELECT ‘2‘ UNION SELECT ‘3‘ UNION SELECT ‘4‘ UNION SELECT ‘5‘ UNION SELECT ‘6‘ UNION SELECT ‘7‘ ) AS a ) AS b ,(SELECT @i:=-1) AS i