Subject | Re: [firebird-support] SQL Question |
---|---|
Author | Arno Brinkman |
Post date | 2003-09-05T07:54:57Z |
Hi Michael,
- Stored Procedure.
- sub-selects :
SELECT
(SELECT Value FROM AnotherTable at
WHERE at.ProductKey = p.ProductKey and
at.Year = 2003 and at.Month = 1) AS "1",
(SELECT Value FROM AnotherTable at
WHERE at.ProductKey = p.ProductKey and
at.Year = 2003 and at.Month = 2) AS "2",
....
(SELECT Value FROM AnotherTable at
WHERE at.ProductKey = p.ProductKey and
at.Year = 2003 and at.Month = 12) AS "12",
FROM
Products p
Regards,
Arno
> I have a table with products.Different options.
> To this table is another table with 1 record / month.
> To each month there is MAX 1 record. Sometimes none.
>
> i.e
> MyProduct 2003 1 SomeValue
> MyProduct 2003 2 SomeValue
> MyProduct 2003 3 SomeValue
> MyProduct 2003 5 SomeValue
>
> etc.
>
> I have a customer, that would like to see the values 12 month back in
> time
> on a single line.
> Someting like this:
>
> My Product 01/2003 02/2003 03/2003 04/2003 etc
> value value value value
- Stored Procedure.
- sub-selects :
SELECT
(SELECT Value FROM AnotherTable at
WHERE at.ProductKey = p.ProductKey and
at.Year = 2003 and at.Month = 1) AS "1",
(SELECT Value FROM AnotherTable at
WHERE at.ProductKey = p.ProductKey and
at.Year = 2003 and at.Month = 2) AS "2",
....
(SELECT Value FROM AnotherTable at
WHERE at.ProductKey = p.ProductKey and
at.Year = 2003 and at.Month = 12) AS "12",
FROM
Products p
Regards,
Arno