Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: query help
Hello,
<samuels_at_blue.seas.upenn.edu> wrote in message
news:c3ndq4$629t$1_at_netnews.upenn.edu...
> okay, i have a problem and would like some help.
>
> table:
> TESTING_TABLE
> -------------
> COST_CODE NUMBER,
> REGION VARCHAR2(5),
> ACCOUNT_NUMBER NUMBER,
> CUSTOMER_ID VARCHAR2(10)
> RELATIONSHIP_CODE VARCHAR2(4)
>
>
> for each cost_code , region , and account_number combination, there can be
many customer_id/relationship_code combinations:
> COST_CODE REGION ACCOUNT_NUMBER CUSTOMER_ID
RELATIONSHIP_CODE
> --------- ------- ------------------------------ -------------------------
----- -----------------COS
> 12345 PAW 1234567890123456 0100046556ABCD
TEW
> 12345 PAW 1234567890123456 0101194150ABCD
TEW
> 12345 PAW 1234567890123456 0102191700ABCD
RET
> 12345 PAW 1234567890123456 0102191701ABCD
BUI
> 12345 PAW 1234567890123456 0102191702ABCD
BUI
> 12345 PAW 1234567890123456 0102195380ABCD
TEW
> 12345 PAW 1234567890123456 0102195448ABCD
TRE
> 12345 PAW 1234567890123456 0102412870ABCD
COS
> 12345 PAW 1234567890123456 0102413067ABCD
LPO
> 12345 PAW 1234567890123456 0102413566ABCD
If I understand your task correctly, then this will produce the hree minimums:
select cost_code, region, account_number,
min(case when relationship_code in ('BUI','COD','LPO','TRE') then
customer_id end) min1,
min(case when relationship_code not in ('BUI','COD','LPO','TRE') and
relationship_code='PAR' then customer_id end) min2,
min(case when relationship_code not in ('BUI','COD','LPO','TRE','PAR')
then customer_id end) min3
from testing_table
group by cost_code, region, account_number
VC Received on Tue Mar 23 2004 - 06:15:05 CST