SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating a simple View
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

njguy
Starting Member

USA
16 Posts

Posted - 05/20/2012 :  21:40:29  Show Profile  Reply with Quote
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 amount

SELECT UserType, COUNT(*) AS TypeCount
FROM dbo.Ideas
WHERE (Approved = 'Y') AND (Refrence IS NOT NULL)
GROUP BY UserType

An example result set would look like the following


Customer 10 50%
Emplyee 10 50%

Thanks

Tom

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/20/2012 :  21:44:04  Show Profile  Reply with Quote

SELECT UserType, COUNT(*) AS TypeCount, COUNT(*) * 100.0 / COUNT(*) OVER() AS Percentage
FROM dbo.Ideas
WHERE (Approved = 'Y') AND (Refrence IS NOT NULL)
GROUP BY UserType



KH
Time is always against us

Go to Top of Page

njguy
Starting Member

USA
16 Posts

Posted - 05/20/2012 :  21:54:32  Show Profile  Reply with Quote
quote:
Originally posted by khtan


SELECT UserType, COUNT(*) AS TypeCount, COUNT(*) * 100.0 / COUNT(*) OVER() AS Percentage
FROM dbo.Ideas
WHERE (Approved = 'Y') AND (Refrence IS NOT NULL)
GROUP BY UserType



KH
Time is always against us





I am getting a strange result set

Customer 33 1650.000000000000
Employee 27 1350.000000000000
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/20/2012 :  22:11:50  Show Profile  Reply with Quote
Oops sorry,
should be

COUNT(*) * 100.0 / SUM(COUNT(*)) OVER() AS Percentage



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000