From: | "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Table transform query |
Date: | 2007-09-18 13:12:25 |
Message-ID: | 6C0CF58A187DA5479245E0830AF84F4218CF1F@poweredge.attiksystem.ch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi,
I'm trying to find out how to transform this kind of table data (history
of rental data in a firm):
date serial delivery
----------------------
1 1 L
1 2 L
1 3 L
2 1 R
2 2 R
2 4 L
3 5 L
3 3 R
3 4 R
4 1 L
... into this:
serial dateL dateR
--------------------
1 1 2
1 4
2 1 2
3 1 3
4 2 3
5 3
Basically, data on table 1 means:
- on date 1, product with serial 1 is sent to the customer
- on date 1, product with serial 2 is sent to the customer
- on date 1, product with serial 3 is sent to the customer
- on date 2, product with serial 1 comes back
...
On table 2, data means:
- Product with serial 1 is sent to the customer on date 1, and comes
back on date 2
- Product with serial 1 is sent to the customer on date 4, and hasn't
come back yet
...
Do you think there is a generic SQL solution to this problem, like
crosstab or pivot table?
I'm thinking of doing things in a "procedural" plpgsql manner...
Any idea is welcome.
Thanks!
Philippe
From | Date | Subject | |
---|---|---|---|
Next Message | Philippe Lang | 2007-09-18 13:49:47 | Re: Table transform query |
Previous Message | Sabin Coanda | 2007-09-18 10:55:08 | error dropping operator |