题解 | where、子查询、左连接
返回购买 prod_id 为 BR01 的产品的所有顾客的电子邮件(一)
https://www.nowcoder.com/practice/962b16554fbf4b99a87f4d68020c5bfb
总结
1.子查询
SELECT cust_email FROM Customers WHERE cust_id IN ( SELECT cust_id FROM Orders WHERE order_num IN ( SELECT order_num FROM OrderItems WHERE prod_id = 'BR01' ) );
2. where
select cust_email from Customers,OrderItems,Orders where Customers.cust_id=Orders.cust_id and Orders.order_num=OrderItems.order_num and OrderItems.prod_id = 'BR01'
3.左连接
select cust_email from Customers AS c left join Orders as o on c.cust_id = o.cust_id left join OrderItems as oi on oi.order_num = o.order_num where oi.prod_id = 'BR01'