I have 2 tables customer and orders. Each customer can place multiple orders
customerhas a columncustomer_numordershas columnsorder_num, customer_num
I want the results to show like this:
Here is my current code which only returns all the distinct customer num
select distinct c.customer_num from customer c inner join orders o on o.CUSTOMER_NUM = c.customer_num
Advertisement
Answer
Try the below – using count() aggregation with group by
select c.customer_num,count(order_num) from customer c inner join orders o on o.CUSTOMER_NUM = c.customer_num group by c.customer_num
