Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert to % for a count SQL

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           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

like image 696
icecurtain Avatar asked Apr 08 '26 19:04

icecurtain


1 Answers

SELECT   del_cd, COUNT(DEL_CD) * 100.0 / SUM(COUNT(DEL_CD)) OVER ()
FROM     datastore
GROUP BY
         del_cd
like image 187
Quassnoi Avatar answered Apr 11 '26 15:04

Quassnoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!