Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get % for repeated list

Author  Topic 

bulubuk1976
Starting Member

24 Posts

Posted - 2011-02-27 : 21:48:44

Hi!

I need help on how I can include % of count againts the total. Below is my sql statement. Don't know how:

SELECT Count(UID), Level1 as Lvl1Count
FROM dbo.View_table1 Group by Level1

Count % Level 1
10 ? OThers
21 ? aControllable
33 ? aUncontrollable
178 ? bControllable
9 ? bUncontrollable


Thank you for the help.

chris_n_osborne
Starting Member

34 Posts

Posted - 2011-02-28 : 00:06:45
Try dividing COUNT(UID) by COUNT(*), multiply by 100, and use CAST/CONVERT as necessary.

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-28 : 04:36:23
if you are using SQL 2005 / 2008

count(UID) * 100.0 / sum(count(UID)) over() as [%]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -