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.
You can use
CASEstatements 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