有两个表:
customer
:cust_id
和details of customer address
order
- ord_id
,cust_id
,ord_quantity
对于一个cust_id
,有许多orders
,即许多ord_id
答案 0 :(得分:-1)
SELECT
c.*,
o.total_order
FROM customer c
LEFT JOIN (
SELECT
cust_id,
count(*) AS total_order
FROM ORDER
GROUP BY cust_id
HAVING count(*) > 4
) o
ON o.cust_id = c.cust_id
WHERE
o.cust_id IS NOT NULL;
它应该返回欲望结果