Reputation: 393
I've a table containing information as follows:
idnumber applic_id cctype ccnumber
--------- ------------ -------- ----------
1 23 1 223445
2 23 2 345567
I need a query that an make this:
idnumber applic_id cctype ccnumber idnumber applic_id cctype ccnumber
--------- ------------ -------- ---------- --------- ------------ -------- ----------
1 23 1 223445 2 23 2 345567
Is anyone have a clue? I'm using PostgreSQL 8.3.
Upvotes: 1
Views: 6034
Reputation: 35613
This is known as a PIVOT.
You can do it either with the PIVOT keyword which does not exist in PostgreSQL, or using the poor-man's pivot like this:
Poor Man's Pivot:
Upvotes: 0
Reputation: 656321
You can use CASE
statements for simple queries.
Or use the crosstab()
function of the tablefunc module for more complex cases and better performance.
You can find examples for both cases under this related question:
PostgreSQL Crosstab Query
Upvotes: 1