题解 | #返回购买 prod_id 为 BR01 产品#

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

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

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 c.cust_email
FROM Customers c
JOIN Orders o ON c.cust_id = o.cust_id
JOIN OrderItems oi ON o.order_num = oi.order_num
WHERE oi.prod_id = 'BR01'

跟着行文逻辑就直接写出来了,但是一直子查询好像会重复扫描表格,因此用join会比较好

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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