mysql查询当天时间段的sql语句怎么写呢

2025-02-22 11:38:20
推荐回答(2个)
回答1:

你的问题描述的不够明确,不太清楚你要的效果,这样,给你两种效果:
1、显示某个时间段的数据:
select * from tb where hour(col_datetime)=18 and to_days(col_datetime)=to_days(curdate())
2、按时间段排序,显示当天所有时间段数据:
select '今天'+cast(hour(col_datetime) as varchar(2))+'时发布的内容',* from tb where to_days(col_datetime)=to_days(curdate()) order by col_datetime

回答2:

select hour(时间),sum(数量) from table where date(时间)=date(now()) group by hour(时间)