Subject Re: Row 2 column
Author Milan Babuskov
> From: "SyamSyah" <syamsyah@...>
> Subject: Re: Row 2 column
>
> Thank's for ur comment. But.. i can do it in oracle, i use DECODE
> function. There are any function like DECODE (oracle) in
> firebird/interbase ?
>
> This the query :
>
> SELECT
> REK,
> SUM(DECODE(JNR, '112', 1, 0)*ANG) AS R112,
> SUM(DECODE(JNR, '321', 1, 0)*ANG) AS R321,
> SUM(DECODE(JNR, '491', 1, 0)*ANG) AS R491,
> SUM(ANG) AS TOTAL
> FROM RTABLE
> GROUP BY REK;
>
> .: SyamSyah :.

Well, if you are going to put literal values ('112', '321', '491') than you
can write view like this:

Create view Rek_view (rek, r112, r321, r491)
as
SELECT REK,
(SELECT SUM(ANG) FROM RTABLE r2
WHERE r1.rid = r2.rid AND r2.JNR ='112') AS R112,
(SELECT SUM(ANG) FROM RTABLE r2
WHERE r1.rid = r2.rid AND r2.JNR ='321') AS R321,
(SELECT SUM(ANG) FROM RTABLE r2
WHERE r1.rid = r2.rid AND r2.JNR ='491') AS R491,
FROM rtable r1

Then you select from it like this:

SELECT REK, SUM(r112), SUM(r321), SUM(r491)
FROM Rek_view
GROUP BY REK

Not very nice, but should work.

HTH,

--
Milan Babuskov
http://sourceforge.net/projects/fbexport