Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Total CustID
200 1
800 2
500 3

i want to calulate % of each Cust Id using Sql command only.
Posted

So perhaps something like
SQL
SELECT a.CustId,
      (a.Total / b.AbsoluteFinalTotal) * 100
FROM MyTable a,
     (SELECT SUM(Total) AS AbsoluteFinalTotal
      FROM MyTable) b;
 
Share this answer
 
v2
Comments
Shrikesh_kale 13-Feb-15 1:23am    
select Sum(Ammount) as Total,CustID from Sales group by CustID
privious command . there no column of Total.
Thanks7872 13-Feb-15 1:54am    
Atleast you should care to change column names. No one will be providing you whole code. He just explained the concept.
Wendelius 13-Feb-15 9:15am    
Thank you Rohan :)
Shrikesh_kale 13-Feb-15 1:56am    
thanks i done it
SQL
Select Total, (Total* 100 / (Select sum(Total) From MyTable)) as Score
From MyTable
Group By Total
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900