Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> SQL: Counting occurances
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
![]() |
![]() |