Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DECODE a negative sum

604717Jun 16 2008 — edited Jun 16 2008
Hello,
i'm not quite sure if this is the right forum but i wil post my question here.
I want to use a decode statement to get the sum of different topics. My SQL-statement looks like:

select * from
(SELECT month time,
MAX(decode(vcgmk, 'BMW', sum, 0)) BMW,
MAX(decode(vcgmk, 'Porsche', sum, 0)) Porsche,
MAX(decode(vcgmk, 'GM', sum, 0)) GM,
MAX(decode(vcgmk, 'Dodge', sum, 0)) Dodge
FROM
(SELECT TRUNC(date, 'MON') month,
SUM(nwert) as sum,
vcgmk
FROM tab_wak
WHERE(date BETWEEN to_date('01.05.2008 00:00', 'dd.mm.yyyy hh24:mi')
AND to_date('07.05.2008 23:59', 'dd.mm.yyyy hh24:mi'))
GROUP BY TRUNC(date, 'MON'),
vcgmk)
GROUP BY month)

This works fine while the sum is positive. Is the sum negative, the decode-statement returns the default value. And if i switch the default value to null, the sum will be returned correctly but the columns will be null. is there a opportunity to combine both, to get the negativ sum and default value as literal null?

Thanks so far!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2008
Added on Jun 16 2008
8 comments
2,240 views