1

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.

0

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

6 Comments

thanks for the quick answer, but when I tried this crosstab function it gave me an error - "ERROR: function crosstab(unknown) does not exist"
@dna: You need to install the additional module tablefunc. Follow my link and read my answer there.
I can't install anything because I'm not administrator on the server :) that is why I'll have to find another way to handle the problem :) thanks for the replay anyway :)
@dna I presented two alternatives. The linked question has answers for both.
Sorry but I'm new in this forum, and I can't find the answers in the link you presented, it just opens your profile.
|
0

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:

3 Comments

This is tagged [PostgreSQL], there is no PIVOT keyword. You may be thinking of SQL Server.
@ErwinBrandstetter, That is why the poor-man's pivot in the link.
@ErwinBrandstetter, ok it was linked from the one I linked from!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.