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 -> SQL: Counting occurances

SQL: Counting occurances

From: Doug Bonson <tbarry_at_uspe.com>
Date: 1998/02/04
Message-ID: <34d8e435.74145328@news.supernews.com>#1/1

Given the following two tables:

create table Customer
(cust_id number(6),

   cust_type number(1))

1, 1
2, 2
3, 1
4, 1
5, 2

create table Orders
(order_id number(7),

   cust_id number(6))

1, 1
2, 2
3, 3
4, 1
5, 5
6, 2
7, 1

How can I get a list of all customers of type 1 with their respective number of orders? Note that some customers may have no orders.

Result set (for type = 1) should be:

1, 3 (customer 1 has 3 orders)
3, 1 (customer 3 has 1 order)
4, 0 (customer 4 has 0 orders)

Thanks,
Doug Received on Wed Feb 04 1998 - 00:00:00 CST

Original text of this message

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