COUNT(*) OVER() gives you the total.
Change In fact, you need SUM(COUNT(MyTbl.ItemID)) OVER() when you sum the values ββin this column.
SELECT Items.ItemID, [count] = COUNT(MyTbl.ItemID), [Percent] = 100.0 * COUNT(MyTbl.ItemID) / SUM(COUNT(MyTbl.ItemID)) OVER() FROM (VALUES (1,'N1'), (2,'N2'), (3,'N4'), (4,'N5')) Items(ItemID, ItemName) LEFT JOIN (VALUES(1), (1), (3), (4), (4), (4)) MyTbl(ItemID) ON ( MyTbl.ItemID = Items.ItemID ) GROUP BY Items.ItemID ORDER BY Items.ItemID
Martin smith
source share