题解 | #返回购买 prod_id 为 BR01 的产品的所有顾客的电子邮件(一)#
返回购买 prod_id 为 BR01 的产品的所有顾客的电子邮件(一)
http://www.nowcoder.com/practice/962b16554fbf4b99a87f4d68020c5bfb
三层子查询,先从最里层写,查询到prod_id ="BR01"的订单编号
select order_num from OrderItems where prod_id ="BR01"
查询到prod_id ="BR01"的客户id
select cust_id from Orders where order_num in (select order_num from OrderItems where prod_id ="BR01")
查询到prod_id ="BR01"的客户的邮箱
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"))
当嵌套过多时容易被绕进去