我有以下表格:
Customers (customer_id,customer_name)
Orders (order_id, order_date, customer_id)
Order_details (order_id, item_id)
Items (item_id)
我需要一个oracle sql查询来获取购买多件商品的客户列表。提前谢谢
答案 0 :(得分:1)
这应该这样做,它还包括一个显示订单数量的列:
SELECT Count(item_id) order_count, customer_id, customer_name
FROM Customers
INNER JOIN Orders ON Customers.customer_id = Orders.customer_id
INNER JOIN Order_details ON Orders.order_id = Order_details.order_id
GROUP BY customer_id, customer_name
HAVING Count(item_id) > 1
答案 1 :(得分:0)
试着看看这是否有效:
select c.* from customers c, orders o, order_details od
where c.customer_id = o.customer_id
and o.order_id = od.order_id
group by od.order_id having count(od.item_id) > 1;