This query gets the desired rows -grouped by subject- and I also want to know the items count in each group.
SELECT log.* FROM [hm_deliverylog] AS log
WHERE log.deliveryid IN
(
SELECT MAX([deliveryid]) FROM [hm_deliverylog]
WHERE [deliverytime] > DATEADD(HOUR, -12, GETDATE())
GROUP BY deliverysubject
)
ORDER BY deliveryid DESC
How can I count the groups? Like below?
SELECT joined.groupcount, log.* FROM [hm_deliverylog] AS log
P.S: Imagine the Gmail inbox; it displays the newest message and shows the message count. I want to group the messages with same subject and count them…
One way is to put the
COUNT()calculation in the subquery and instead of usingIN, make that a derived table to be joined: