update: what I was calling coalesce I should have been calling pivot.
I'm extracting some daily usage counts from a log table. I can easily get this data one row per date/item, but I would like to pivot coalesce the columns into a single row.
e.g., I have:
date item-to-be-counted count-of-item
10/1 foo 23
10/1 bar 45
10/2 foo 67
10/2 bar 89
I want:
date count-of-foo count-of-bar
10/1 23 45
10/2 67 89
Here's my current 10g query.
select trunc(started,'HH'),depot,count(*)
from logstats
group by trunc(started,'HH'),depot
order by trunc(started,'HH'),depot;
TRUNC(STARTED,'HH') DEPOT COUNT(*)
------------------------- ---------- --------
10/01/11 01.00.00 foo 28092
10/01/11 01.00.00 bar 2194
10/01/11 02.00.00 foo 3402
10/01/11 02.00.00 bar 1058
update: 11g has a pivot operation. The accepted answer shows how to do this in 9i and 10g.