我有一个客户表和一个订单表我想要计算有多少活跃客户已经制作了超过3个订单,表的结构是这样的:
Customer table
customer_id, name, active
orders table
order_id, details, customer_id
任何帮助?
答案 0 :(得分:0)
试试这个:
SELECT c.customer_id,
c.name
FROM Customer AS c
INNER JOIN orders as o
ON o.customer_id = c.customer_id
WHERE c.active
GROUP BY c.customer_id,
c.name
HAVING COUNT(c.customer_id) > 3