Re: A difficult SQL problem... please help
From: Jurij Modic <jurij.modic_at_mf.sigov.mail.si>
Date: 1998/06/25
Message-ID: <3592a440.6824736_at_www.sigov.si>#1/1
GROUP BY sex;
Date: 1998/06/25
Message-ID: <3592a440.6824736_at_www.sigov.si>#1/1
On Wed, 24 Jun 1998 21:10:27 +0800, Lee Ka Wo <leekawo_at_netvigator.com> wrote:
>Dear Experts,
>
>I get a problem....
>
>If I have a tables full of salary., I need to group them into several
>salary "ranges" like this:
>
> <1000 >=1000 to < 2000 >=2000 to <=2500 >2500
>
>Male 100 200 120 50
>Famale 50 222 30 65
>
>What should I do ??
>
>I wonder whether "decode" and "union" can help me ??
>
>e.g.
>
>Select count(*) , decode (??????) from people group by sex
Try this:
SELECT sex,
SUM(DECODE(SIGN(1000-salary),1,1,0)) '<1000', SUM(DECODE(SIGN(2000-salary),1,1,0)) '>=1000 to <2000', SUM(DECODE(SIGN(2500-salary),1,1,0,10)) '>=2000 to <=2500', SUM(DECODE(SIGN(2500-salary),-1,1,0) '>2500'FROM salary_table
GROUP BY sex;
Regards,
Jurij Modic Republic of Slovenia jurij.modic_at_mf.sigov.mail.si Ministry of Finance ============================================================The above opinions are mine and do not represent any official standpoints of my employer Received on Thu Jun 25 1998 - 00:00:00 CEST