题解 | #返回购买 prod_id 为 BR01 (二)#

返回购买 prod_id 为 BR01 的产品的所有顾客的电子邮件(二)

https://www.nowcoder.com/practice/c7aa73afc41f4dfc925baebdd175c345

# select
#     cust_email
# from
#     Customers 
#     inner join Orders on Customers.cust_id = Orders.cust_id
#     inner join OrderItems on OrderItems.order_num = Orders.order_num
# where 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'  
)
)

多层子查询

从上往下写,发现和别的表关联的字段就使用(select x from 表 where 另外一个字段xx in ())

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 18:06
点赞 评论 收藏
分享
点赞 评论 收藏
分享
码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务