Hello,
I have this query that I run on Oracle 9i:
SELECT DISTINCT
b.amount_code_description,
to_char((CASE
WHEN b.year = '2005' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2005,
to_char((CASE
WHEN b.year = '2006' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2006,
to_char((CASE
WHEN b.year = '2007' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2007
FROM table a
and my result set looks like:
Y2005 Y2006 Y2007
ABC 0.00 0.00 25335.69
ABC 0.00 60868.80 0.00
ABC 15000.05 0.00 0.00
But I would like my result to look like:
Y2005 Y2006 Y2007
ABC 15000.05 60868.80 25335.69
I tried using Sum in the query like this:
SELECT DISTINCT
b.amount_code_description,
to_char(SUM(CASE
WHEN b.year = '2005' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2005,
to_char(SUM(CASE
WHEN b.year = '2006' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2006,
to_char(SUM(CASE
WHEN b.year = '2007' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2007
FROM table a
but then the numbers are all wrong:
Y2005 Y2006 Y2007
ABC 660002.20 2678227.20 1114770.36
I have this query that I run on Oracle 9i:
SELECT DISTINCT
b.amount_code_description,
to_char((CASE
WHEN b.year = '2005' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2005,
to_char((CASE
WHEN b.year = '2006' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2006,
to_char((CASE
WHEN b.year = '2007' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2007
FROM table a
and my result set looks like:
Y2005 Y2006 Y2007
ABC 0.00 0.00 25335.69
ABC 0.00 60868.80 0.00
ABC 15000.05 0.00 0.00
But I would like my result to look like:
Y2005 Y2006 Y2007
ABC 15000.05 60868.80 25335.69
I tried using Sum in the query like this:
SELECT DISTINCT
b.amount_code_description,
to_char(SUM(CASE
WHEN b.year = '2005' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2005,
to_char(SUM(CASE
WHEN b.year = '2006' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2006,
to_char(SUM(CASE
WHEN b.year = '2007' THEN
to_char(b.ytd_amount, '9999999999.99')
ELSE
'0.00'
END),
'999999999990.99') AS Y2007
FROM table a
but then the numbers are all wrong:
Y2005 Y2006 Y2007
ABC 660002.20 2678227.20 1114770.36