查询 某天 早上9点到下午4点的人数

来源:互联网 发布:淘宝写给客户的感谢信 编辑:程序博客网 时间:2024/04/28 14:13

select DATEPART(hh,eq.CreateTime) AS 小时,COUNT(*)AS 记录 from Equipment eq inner join Account a on eq.AccountID=a.AccountID
WHERE datepart(hh,eq.CreateTime)>9 and (datepart(hh,eq.CreateTime)<16)
and DATENAME(day,eq.CreateTime)= DATENAME(day,'2010-03-07')

(最主要的就是这句)

GROUP BY CONVERT(VARCHAR(10),eq.CreateTime,120),DATEPART(hh,eq.CreateTime

 

原始数据:select [Name],CreateTime  from   Equipment

 

 

加上条件查询结果:

 

 

提示:要主要看时间字段的记录