Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> How to get counts and sub_counts of a table with single query?
I'd like to built a VIEW on a SELECT statment which retrieves total counts and some other sub_counts which meet certain WHERE conditions. A row must be returned even there were zero sub_conts. Here is my query and it works as along as all its SELECTs return a value otherwise no rows get selected, I am aware of OUTER JOINs but it only works if there was only one table/view.
SELECT a.col_a, a.tot_cont, b.sub_cont_b, c.sub_cont_c,.. FROM
(SELECT col_a, COUNT(*) tot_cont FROM a_table
GROUP BY col_a) a,
(SELECT col_a, COUNT(*) sub_cont_b FROM a_table
WHERE col_x BETWEEN 10 AND 20
GROUP BY col_a) b,
(SELECT col_a, COUNT(*) sub_cont_c FROM a_table
WHERE col_y > 100
GROUP BY col_a) c
.
.
WHERE a.col_a = b.col_a AND a.col_a = c.col_a;
Received on Fri Jun 13 1997 - 00:00:00 CDT
![]() |
![]() |