[SOLVED] SQL : count percent of each values

Issue

This Content is from Stack Overflow. Question asked by iamHTV

I have a table call Orders, column and values of table, column [Order Priority] have 4 value Critical, High, Medium, Low. Ship_tt have 3 value Som, Tre, Dung.

I want to calculate percentage ‘Som’,’Tre’,’Dung’ of Critical, High, Medium, Low.

Thanks for your help.



Solution

SELECT ORDER_PRIORITY, 100. * COUNT(*) / SUM(COUNT(*)) OVER ()
FROM @T T
GROUP BY ORDER_PRIORITY


This Question was asked in StackOverflow by iamHTV and Answered by Srinivasan Rajasekaran It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?