当前位置:   article > 正文

mysql查询时间段内所有日期 和 小时_mysql 查询对应小时段的数据

mysql 查询对应小时段的数据

返回时间段内所有日期 天

select DATE_FORMAT(date_add('2022-06-01 00:00:00', interval row DAY),'%Y-%m-%d') date from
 ( 
    SELECT @row := @row + 1 as row FROM 
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t,
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2, 
    (SELECT @row:=-1) r
 ) se
 where date_add('2022-06-01 00:00:00', interval row DAY) <= '2022-06-31 23:59:59'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

返回时间段内所有日期 小时

 select DATE_FORMAT(date_add('2022-06-01 00:00:00', interval row HOUR),'%Y-%m-%d %H') date from
 ( 
    SELECT @row := @row + 1 as row FROM 
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t,
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2, 
    (SELECT @row:=-1) r
 ) se
 where date_add('2022-06-01 00:00:00', interval row HOUR) <= '2022-06-01 23:59:59';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/406435
推荐阅读
相关标签
  

闽ICP备14008679号