题解 | 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'


全部评论
用不着左连接吧,内连接就可以
2 回复 分享
发布于 2022-12-09 05:35 重庆
select cust_email from Customers join Orders on Customers.cust_id = Orders.cust_id join OrderItems on Orders.order_num = OrderItems.order_num and prod_id = 'BR01'
点赞 回复 分享
发布于 2024-10-13 15:25 湖南
你这个写的真复杂
点赞 回复 分享
发布于 2022-08-09 22:51

相关推荐

点赞 评论 收藏
分享
Rena1ssance_:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
评论
37
7
分享

创作者周榜

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