1.列出A表中,time大于当天10点,小于等于当天12点的时间范围内,每个小时的记录(数据)个数,并按照time字段排序(倒序)。时间格式YYYY-MM-DD HH24:MI:SS.
2.选出A表中time大于当天9点的数据中,b的最大值和平均值。
1.列出A表中,time大于当天10点,小于等于当天12点的时间范围内,每个小时的记录(数据)个数,并按照time字段排序(倒序)。时间格式YYYY-MM-DD HH24:MI:SS.
2.选出A表中time大于当天9点的数据中,b的最大值和平均值。
1、select datepart(hh, time) as _hour,count(1) as _count from A where datediff(hh,getdate(),time)>10 and datediff(hh,getdate(),time)<=12 group by datepart(hh, time) order by time desc
2、select max(b) as _maxB,avg(b) as _avgB from A where datediff(hh,getdate(),time)>9
select datepart(hour,ttime ), count(*) from Table_time where ttime between '2009-01-01 10:00:00' and '2009-01-01 12:00:00'
group by datepart(hour,ttime )
每个小时的记录(数据)个数
select count(*) from Table_time where ttime between '2009-01-01 10:00:00' and '2009-01-01 12:00:00'
按照time字段排序(倒序)
select * from Table_time where ttime between '2009-01-01 10:00:00' and '2009-01-01 12:00:00' order by ttime desc
选出A表中time大于当天9点的数据中,b的最大值和平均值。
select max(tname),avg(id) from Table_time where ttime > '2009-01-01 09:00:00'
时间可以任意改,我只是在我的數據庫里测试一下而已。
1 select * from A where datepart(hour,time) > 10 and datepart(hour,time)<12 order by time desc
2 select max(b), avg(b) from A where datepart(hour,time)>9