我如何使用计数来查看"消息"列数"小时" SQL中一个月之间的列?

时间:2017-12-05 06:12:54

标签: sql database

我想计算每个小时与列日期分隔的消息,我写这个查询但是每个重复小时显示1条消息,有人可以帮忙吗?感谢

Select MsgCount,ReadTime 
From (Select Count(MsgID) MsgCount, 
      LTRIM(RIGHT(CONVERT(VARCHAR(20), mDate, 100), 7)) as ReadTime
      FROM (Select  ReadDate as mDate,
            Convert (TIME, ReadDate) as ReadTime,MessageID as MsgID 
            From QUEUE_BOOKINGQUEUE 
            WHERE MessageID like '%Transaction%'
            AND ReadDate BETWEEN '2017-11-01' AND '2017-11-30') 
      s1
      Group by mDate
) A
Group by MsgCount,ReadTime
Order by 2

1 个答案:

答案 0 :(得分:0)

enter image description here

它与我合作,因为这张照片没有重复 所以,如果你想删除分组,它将是这样的:

Select MsgCount,ReadTime 
From (Select Count(MsgID) MsgCount, 
      LTRIM(RIGHT(CONVERT(VARCHAR(20), mDate, 100), 7)) as ReadTime
      FROM (Select  ReadDate as mDate,
            Convert (TIME, ReadDate) as ReadTime,MsgID as MsgID 
            From QUEUE_BOOKINGQUEUE 
    )  s1
      Group by mDate,s1.MsgID
) A