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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to calculate Percentage?

Author  Topic 

daipayan
Posting Yak Master

181 Posts

Posted - 2009-12-01 : 02:13:54
Hi all,
I have a table name: Feedback, under that following are the column:-
----------------------
ID | Qs1 | Qs2 | Qs3
----------------------
1 | 2 | 1 | 4
2 | 2 | 1 | 1
3 | 3 | 1 | 2
4 | 2 | 1 | 3
----------------------

Now I want calculate the feedback in following way:
No. of 2 in Qs1 is 3
No. of 3 in Qs1 is 1
& Total No. is 4
So the percentage for 2 is ((3/4)*100) & 3 is ((1/4)*100)
The same way I want to calculate for Qs2 & Qs3

I got the following query, but I am not able to calculate the percentage:
SELECT
(SELECT count(Qs1) FROM dbo.Feedback where Qs1 = '2'),
count(ID)
FROM dbo.Feedback


Hope I can make you understand my query!

Daipayan

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-01 : 07:47:51
SELECT
sum(case when Qs1='2' then 1 else o end)*100.0/count(ID) as no_of_2,
sum(case when Qs1='3' then 1 else o end)*100.0/count(ID) as no_of_3
FROM dbo.Feedback

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -