Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Percentage Question

Status
Not open for further replies.

lyric0n

Technical User
Dec 28, 2005
74
I have listed data in a table and need to find the percentage of each occurance, so similar to a count, but instead of returning the total count, I need a percentage of the total.

So...

Column
Type1
Type1
Type2
Type3

I need to have it return data in the form...
Name | Percent
Type1 | 50.00
Type2 | 25.00
Type3 | 25.00

I do also need 2 decimals in my remainder has I will have some small percentages.

Thanks,
Chris
 
Code:
Select 	[!]Column[/!], Convert(Decimal(10,2), 1.0 * Count([!]Column[/!]) / (Select Count([!]Column[/!]) From [!]Table[/!])) As Percentage
From 	[!]Table[/!]
Group By [!]Column[/!]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top