Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> How to get counts and sub_counts of a table with single query?

How to get counts and sub_counts of a table with single query?

From: Adm Tadj <vahidt_at_dbsun.vitek.com>
Date: 1997/06/13
Message-ID: <33A15D91.2DF6@dbsun.vitek.com>#1/1

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US