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
Loading
Suthish NairPosted Jan 25, 2012, 4:21 AM
Pramod ShivharePosted Jan 25, 2012, 2:00 AM
but this query is not fulfilling my second requirement. As i said when count for any interval say 31-60 is 0, then in result i should get 0 for 31-60 interval. but here i am not getting any row for the interval whose count is 0.
RohitPosted Jan 25, 2012, 1:38 AM
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 ORDER BY AgeRange;