I'm using the following query, I need to show Grand Total count but it is throwing error like
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
SELECT
ISNULL(OQ.GroupID,'') GroupName,
CONVERT(VARCHAR, ISNULL(COUNT(CASE WHEN RequestStatusKey IN ( 1, 2 ) THEN OrderRecordID END), 0)) TotalRecord,
SUM(COUNT(CASE WHEN RequestStatusKey IN ( 1, 2 ) THEN OrderRecordID END)) AS GrandTotal
FROM dbo.tblDesk OQ
WHERE OQ.RequestStatusKey IN ( 1, 2 )
AND OQ.OrderTypeKey <> 1
AND OQ.GroupID IS NOT NULL
GROUP BY OQ.GroupID
ORDER BY OQ.GroupID
I just need to Grand total.

WITH ROLLUPor do you want a separate column that counts the totals altogether (which you could achieve with something like anSUM(COUNT(...)) OVER())? - ZLK