正在寻找连接两个表的SQL行,但在
上填充它答案 0 :(得分:1)
a)每位客户的订单数量。
SELECT C.NAME, COUNT(O.id)
FROM Customers C
INNER JOIN Orders O ON O.customer_id = C.ID
GROUP BY C.NAME
b)拥有三个或更多订单的所有客户的清单。
SELECT C.NAME, COUNT(O.id)
FROM Customers C
INNER JOIN Orders O ON O.customer_id = C.ID
GROUP BY C.NAME
HAVING COUNT(O.id) > 3
c)订购名为“测试项目”的项目的所有客户的清单。
SELECT C.NAME, COUNT(O.id)
FROM Customers C
INNER JOIN Orders O ON O.customer_id = C.ID
WHERE O.item_name = 'test item'
GROUP BY C.NAME
d)未订购名为“测试项目”的项目的所有客户的清单。
SELECT C.NAME, COUNT(O.id)
FROM Customers C
INNER JOIN Orders O ON O.customer_id = C.ID
WHERE O.item_name <> 'test item'
GROUP BY C.NAME