Subject Re: [ib-support] Re: Row 2 column
Author SyamSyah
Finally... it work! i'm not write view, direct to select... group by... like this :

SELECT r1.REK,
(SELECT SUM(ANG) FROM rtable
WHERE JNR ='112' AND rid = r1.rid),
(SELECT SUM(ANG) FROM rtable
WHERE JNR ='321' AND rid = r1.rid),
(SELECT SUM(ANG) FROM rtable
WHERE JNR ='491' AND rid = r1.rid),
SUM(ANG) AS TOTAL
FROM rtable r1
GROUP BY REK;

Many thanks.

.: SyamSyah :.

----- Original Message -----
From: Milan Babuskov
Subject: [ib-support] Re: Row 2 column


welll, 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,


[Non-text portions of this message have been removed]