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 |
|
njguy
Starting Member
16 Posts |
Posted - 2012-05-20 : 21:40:29
|
| I was creating the VIEW below and at this point it works just fine but I want to add another column to show it as a percentage of the toal amountSELECT UserType, COUNT(*) AS TypeCountFROM dbo.IdeasWHERE (Approved = 'Y') AND (Refrence IS NOT NULL)GROUP BY UserTypeAn example result set would look like the followingCustomer 10 50%Emplyee 10 50%ThanksTom |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-20 : 21:44:04
|
[code]SELECT UserType, COUNT(*) AS TypeCount, COUNT(*) * 100.0 / COUNT(*) OVER() AS PercentageFROM dbo.IdeasWHERE (Approved = 'Y') AND (Refrence IS NOT NULL)GROUP BY UserType[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
njguy
Starting Member
16 Posts |
Posted - 2012-05-20 : 21:54:32
|
quote: Originally posted by khtan
SELECT UserType, COUNT(*) AS TypeCount, COUNT(*) * 100.0 / COUNT(*) OVER() AS PercentageFROM dbo.IdeasWHERE (Approved = 'Y') AND (Refrence IS NOT NULL)GROUP BY UserType KH[spoiler]Time is always against us[/spoiler]
I am getting a strange result setCustomer 33 1650.000000000000Employee 27 1350.000000000000 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-20 : 22:11:50
|
Oops sorry, should be COUNT(*) * 100.0 / SUM(COUNT(*)) OVER() AS Percentage KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|