I have a pretty basic sql query query that is doing a calculation on the total number of records returned from a grouped result set.
SELECT vco.OutcomeName,
vco.VersionCompareOutcomeID,
COUNT(t.OutcomeName) AS Total,
ROUND(COUNT(*) * 100.0 / sum(count(*)), 1) over() AS Percentage
FROM map.VersionCompareOutcome AS vco
LEFT JOIN @temp AS t
ON vco.VersionCompareOutcomeID = t.VersionCompareOutcomeID
GROUP BY vco.OutcomeName, vco.VersionCompareOutcomeID
When I try and use the round
function, I am getting the following error: The function 'ROUND' is not a valid windowing function, and cannot be used with the OVER clause.
Without the round
function, I get the percentage but its not rounded like I am trying to achieve.
My desired outcome would be 2 decimal places: 87.95%
for example.