SQL question - need help to get a nicer result presentation
Hello Guys!I got a sql that I need some help with.
[CODE]
select c.CODE, c.NAME,
count(case when pi.TYPE = 'A' then si.RECEIPT_NUMBER else NULL end) as A,
count(case when pi.TYPE = 'B' then si.RECEIPT_NUMBER else NULL end) as B,
count(case when pi.TYPE = 'C' then si.RECEIPT_NUMBER else NULL end) as C
from sold_items si. product_items pi, companies c
where
si.SOLD_DATE between to_date('20101201 00:00', 'YYYYMMDD HH24:MI') AND to_date('20131130 23:59', 'YYYYMMDD HH24:MI')
and
si.FK_PRODUCT_ITEM_ID = pi.ID
and
pi.FK_COMPANY_ID = c.ID
group by c.CODE, c.NAME, pi.TYPE
order by c.CODE, pi.TYPE
[/CODE]
Result gets like this:
[CODE]
CODE NAME A B C
111111 Company A 2591 0 0
111111 Company A 0 57239 0
111111 Company A 0 0 284427
222222 Company B 695 0 0
222222 Company B 0 22060 0
222222 Company B 0 0 124277
[/CODE]
But I would like to get it like this:
[CODE]
111111 Company A 2591 57239 284427
222222 Company B 695 22060 124277
[/CODE]
Do you guys see any solution?
Best regards
Fredrik