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.
| Author |
Topic |
|
scooternm
Starting Member
8 Posts |
Posted - 2008-07-03 : 13:56:21
|
| I have a table that I want to run a query against with the eventual goal to produce some pie charts.The last column will contain 5 possible values. I want to figure out what percentage each value takes up in the table. So if there are 100,000 entries andValue1=10,000 timesValue2=40,000 timesValue3=5,000 timesValue4=25,000 timesValue5=20,000 timesI want a query that produces the following results:10%40%5%25%20%Can anyone help point me in the right direction? Thanks. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-03 : 14:35:41
|
| DECLARE @table TABLE (Col1 int)INSERT INTO @tableSELECT 1 union allSELECT 1 union allSELECT 1 union allSELECT 2 union allSELECT 2 union allSELECT 5 union allSELECT 6SELECT Col1,count(*),count(*)*100.0/(select count(*) from @table)FROM @tableGROUP BY col1Jim |
 |
|
|
scooternm
Starting Member
8 Posts |
Posted - 2008-07-03 : 15:18:45
|
| Thanks, I think I got it! |
 |
|
|
|
|
|