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.
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.