题解 | 在子查询中使用inner join、Using函数

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

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

-- 纯inner join
# SELECT
# 	c.cust_email 
# FROM
# 	Customers c
# 	INNER JOIN Orders o ON c.cust_id = o.cust_id
# 	INNER JOIN OrderItems oi ON oi.order_num = o.order_num 
# WHERE
# 	oi.prod_id = 'BR01' 
-- 子查询+inner join
-- 全凭语法写出来 没点逻辑
SELECT
	c.cust_email 
FROM
	Customers c 
WHERE
	c.cust_id IN (
	SELECT
		cust_id 
	FROM
		Orders
    WHERE
        order_num IN (
            SELECT order_num 
            FROM OrderItems INNER JOIN  Orders USING ( order_num ) 
            WHERE prod_id = 'BR01' )
    )

全部评论

相关推荐

死在JAVA的王小美:哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈,我也是,让我免了一轮,但是硬气拒绝了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务