|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
Ranking counts from multiple columns
I have a table where every record is a questionnaire with three questions. Each question has a yes/no answer:
(can't get this to line up...) QID A B C 1 y n n 2 y y y 3 n n n 4 y n y I need to count the 'yes' answers for each question and then rank them descendingly. Ie. I want a table looking like this: Question Count A 3 C 2 B 1 I have tried individual queries to count each (SELECT Count(a) FROM table WHERE a; ), which gives me the values I need, but I cannot find a way to rank them in a single query. Suggestions? Kate. Last edited by katej : April 8th, 2003 at 07:35 AM. |
|
#2
|
|||
|
|||
|
Code:
select * from ( select 'A' as question,count(*) as total from t where QID = 'A' and A = 'y' union all select 'B',count(*) from t where QID = 'B' and B = 'y' union all select 'C',count(*) from t where QID = 'C' and C = 'y' ) dt order by total desc |
|
#3
|
|||
|
|||
|
With some slight tweaking it works beautifully - thanks a lot!
Kate. |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > Ranking counts from multiple columns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|