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

    技术2022-05-19  20

    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

     

     

    加上条件查询结果:

     

     

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


    最新回复(0)