Subject Re: [firebird-support] help on query
Author Ivan Prenosil
Arno's solution using CASE is probably the fastest, since it will do everything
in single pass. If you want compatibility with FB1/IB, you can try this


CREATE VIEW codes AS
SELECT DISTINCT code
FROM t;

SELECT code,
(SELECT SUM(val) FROM t WHERE code=c.code AND entry_date>='1.1.2003' AND entry_date<'1.2.2003') January,
(SELECT SUM(val) FROM t WHERE code=c.code AND entry_date>='1.2.2003' AND entry_date<'1.3.2003') February,
(SELECT SUM(val) FROM t WHERE code=c.code AND entry_date>='1.3.2003' AND entry_date<'1.4.2003') March
FROM codes c;


Ivan Prenosil
Ivan.Prenosil@...
http://www.volny.cz/iprenosil/interbase


----- Original Message -----
From: "Sudheer Palaparambil" <p_sudheers@...>
> I have a few records in a table like this
>
> Code entry_date value
> ---- ---------- -------
> 01 01.01.2003 200.00
> 01 15.01.2003 1200.00
> 02 30.01.2003 500.00
> 02 08.02.2003 100.00
> 01 15.02.2003 300.00
> 02 04.03.2003 200.00
> 01 01.03.2003 1000.00
> 02 11.03.2003 500.00
>
> and I want to generate a report like this in
> FB 1.5.
>
>
> Code January February March
> -----------------------------------------------
> 01 1400.00 300.00 1000.00
> 02 500.00 100.00 700.00