我想计算每个小时与列日期分隔的消息,我写这个查询但是每个重复小时显示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
答案 0 :(得分:0)
它与我合作,因为这张照片没有重复 所以,如果你想删除分组,它将是这样的:
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