mysql从当前时间往前偏移24小时,和当天24小时sql

  当天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

  

mysql从当前时间往前偏移24小时,和当天24小时sql

上一篇:3.关于tdsql工作中碰到的问题01


下一篇:b站数据库课4之分页查询