Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi, I have the following table: Quantity MONTHApple 49 1 Banana 120 1Orange 55 1The total Quantity is 224 now I need the following result: Percentage MONTHApple 21.8% 1 Banana 53.6% 1Orange 24.5% 1I appreciate your help. Thank you.
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2008-09-05 : 16:54:52
SELECT Column1, Quantity*100.0/(SELECT SUM(Quantity) AS TotalQuantity FROM YourTable), MONTHFROM YourTableTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-09-06 : 23:38:49
small modification (just in case your table has more than one months data
SELECT t.Column1, t.Quantity*100.0/(SELECT SUM(Quantity) AS TotalQuantity FROM YourTableWHERE MONTH=t.MONTH),t.MONTHFROM YourTable t