December 3, 2004 at 9:15 am
I've got a view that basically consists of subqueries to get rollup information. It doesn't translate to oracle, and I can't seem to find a decent oracle example.
The view is pretty simple:
CREATE VIEW BENIFCOUNT_STATS AS
SELECT
ACTTBLKEY,
(SELECT COUNT(ACTTBLKEY) FROM GMHOPBEN WHERE RCVSUPPORTSVC ='Y' AND ACTTBLKEY = A.ACTTBLKEY)AS RCVSUPPORTSVC,
(SELECT COUNT(ACTTBLKEY) FROM GMHOPBEN WHERE RCVHOUSINGAST ='Y' AND ACTTBLKEY = A.ACTTBLKEY)AS RCVHOUSINGAST,
(SELECT COUNT(ACTTBLKEY) FROM GMHOPBEN WHERE RCVLONGTERM ='Y' AND ACTTBLKEY = A.ACTTBLKEY)AS RCVLONGTERM,
(SELECT COUNT(ACTTBLKEY) FROM GMHOPBEN WHERE RCVSHORTTERM ='Y' AND ACTTBLKEY = A.ACTTBLKEY)AS RCVSHORTTERM
FROM GMHOPBEN A
GROUP BY ACTTBLKEY,RCVSUPPORTSVC,RCVHOUSINGAST,RCVLONGTERM,RCVSHORTTERM
Can anyone give me a hint or example of an oracle view that does a rollup of information like this?
Lowell
December 3, 2004 at 10:28 am
Hi Lowell,
My PL/SQL is sort of rusty, but I think GROUP BY isn't allowed in a view definition. Try leaving that out of the CREATE VIEW and using it in your SELECT from the view instead.
Greg
Greg
December 3, 2004 at 10:44 am
Actually, i figured out a different way to get the totals; rather than using that subquery to get the count, i'm using a group by to count case statements, which works in both SQL and Oracle using the same syntax:
SELECT
ACTTBLKEY,
SUM (CASE WHEN RCVSUPPORTSVC ='Y' THEN 1 ELSE 0 END) AS RCVSUPPORTSVC,
SUM (CASE WHEN RCVHOUSINGAST ='Y' THEN 1 ELSE 0 END)AS RCVHOUSINGAST,
SUM (CASE WHEN RCVLONGTERM ='Y' THEN 1 ELSE 0 END)AS RCVLONGTERM,
SUM (CASE WHEN RCVSHORTTERM ='Y' THEN 1 ELSE 0 END)AS RCVSHORTTERM
FROM GMHOPBEN
GROUP BY ACTTBLKEY ;
thanks for reading this!
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply