|
Posted by Serge Rielau on 03/30/06 03:11
bogtom@gmail.com wrote:
> I have records
>
> ID Sku Name Date
> 2 41 Blair 01/04/03
> 3 45 John 03/04/03
>
> that should look like...
>
> ID 2 3
> Sku 41 45
> Name Blair John
> ....
>
> and so on. Number of source rows will be fixed (12) so no of target
> columns will be 12 too.
>
> Anyone know of a quick way to do this via simple SQL ?
>
This should work on all RDBMS:
CREATE TABLE Sales(Year INTEGER,
Quarter INTEGER,
Results INTEGER);
SELECT Year,
MAX(CASE WHEN Quarter = 1
THEN Results END) AS Q1,
MAX(CASE WHEN Quarter = 2
THEN Results END) AS Q2,
MAX(CASE WHEN Quarter = 3
THEN Results END) AS Q3,
MAX(CASE WHEN Quarter = 4
THEN Results END) AS Q4
FROM Sales
GROUP BY Year
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Navigation:
[Reply to this message]
|