COUNT(*) OVER()
ger dig det totala antalet.
Redigera Men egentligen behöver du SUM(COUNT(MyTbl.ItemID)) OVER()
eftersom du summerar värdena i den kolumnen.
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