Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORACLE SQL Question

Status
Not open for further replies.

ADB1

Programmer
Aug 24, 2001
235
GB
I am trying to get to the following results using oracle sql:

Age Total Amount
<7 17
Ontime 34
1 - 7 124
>7 16

The sql I am trying to use is below:
SELECT
CASE WHEN ZEUS.SPEC_ORD.SRBD - MAX(ZEUS.SPEC_ORD_STAT_HIST.STAT_CHANG_DATE) <-7 THEN '<-7' WHEN ZEUS.SPEC_ORD.SRBD - MAX(ZEUS.SPEC_ORD_STAT_HIST.STAT_CHANG_DATE) BETWEEN -7 AND 0 THEN 'Ontime' WHEN ZEUS.SPEC_ORD.SRBD - MAX(ZEUS.SPEC_ORD_STAT_HIST.STAT_CHANG_DATE) BETWEEN 1 AND 7 THEN '1 to 7'WHEN ZEUS.SPEC_ORD.SRBD - MAX(ZEUS.SPEC_ORD_STAT_HIST.STAT_CHANG_DATE) >7 THEN '>7'
ELSE NULL END,
Count(ZEUS.SPEC_ORD.VIN17)
FROM
ZEUS.SPEC_ORD,
ZEUS.SPEC_ORD_STAT_HIST
WHERE ( ZEUS.SPEC_ORD.SPEC_ORD_NUMB=ZEUS.SPEC_ORD_STAT_HIST.SPEC_ORD_NUMB )

However, it is giving me Group By errors. When I select a group by column, the results are not what is desired, I get back multiple rows for each age, when what I want to do is sum the ages up.
 
You could try using the DECODE() command which basically works as a series of if statements

SELECT DECODE(col_1,null,col_3,col_5) means

IF col_1=null, select col_3
ELSE select col_5

hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top