Converting rows to columns.

Giganews Newsgroups
Subject: Converting rows to columns.
Posted by:  kpraoa…@yahoo.com
Date: 1 Aug 2006

Hi,

I need to know if there's any analytical function that will convert
rows to columns. Currently, I have a query -
select field1, field2, count(*) from table1 group by field1, field2
order by field1, field2

Obviously, this gives multiple rows for the same value of field1. What
i need is one row for each value of field1 and field2 should appear as
columns.

For example, if the output of the above query is

Field1 field2  count(*)
A        0412  12
A        0501  23
A        0502  25
B        0412  3
B        0501  56

I need the result to be

Field1            0412  0501  0502
A                    12    23      25
B                    3      56

Is that even possible? I thought there was an analytical function that
did this but I dont seem to find it anywhere.

Any help will be greatly appreciated.

Thanks,
KP

Replies