开发者

Convert to % for a count SQL

开发者 https://www.devze.com 2023-02-19 03:34 出处:网络
SELECT DEL_CD ,COUNT(DEL_CD) AS COUNT_NO FROM [DATAStaging].[dbo].[DATASTORE] GROUP BY DEL_CD gives me this result
SELECT DEL_CD ,COUNT(DEL_CD) AS COUNT_NO
FROM [DATAStaging].[dbo].[DATASTORE]
GROUP BY DEL_CD

gives me this result

DEL_CD     COUNT_NO
0   开发者_StackOverflow        6442
1           12161
2           2342

But what do I have to do to the script to display the count number as a %

Total rows does = sum of count_no.

Thanks in advance


SELECT   del_cd, COUNT(DEL_CD) * 100.0 / SUM(COUNT(DEL_CD)) OVER ()
FROM     datastore
GROUP BY
         del_cd
0

精彩评论

暂无评论...
验证码 换一张
取 消