Pramod Shivhare

Pramod Shivhare

  • NA
  • 7
  • 13.7k

Case when problem in SQL

Jan 25 2012 12:52 AM
i have following query working :
SELECT
  COUNT(id), AgeRange
FROM
  (
 
select
    id,
   
case
   
when age < 0 then 'less than 0'
   
when age >= 0 and age <=30 then '0-30'
   
when age >= 31 and age <=60 then '31-60'
   
when age >= 61 and age <=90 then '61-90'
   
when age >= 91 then '91+'
   
when age = null then 'NO INFORMATION'
   
else 'no catagory'
   
end AS AgeRange
 
from queue
 
where DATE between '01-Apr-2011' and '05-May-2011'
  ) T
GROUP BY
  AgeRange;

now my requirement is that, i want these result to printed always in a sequence, first for less than 0, than for 31-60 and so on..
eeven if get count 0 for any interval say 31-60.. it should return 0 for that interval.. can anyone help..thanx in advance

Answers (3)