Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 23、24 关的子查询教学中的示例代码是否有问题? #33

Open
lischen2014 opened this issue Aug 10, 2023 · 2 comments
Open

Comments

@lischen2014
Copy link

lischen2014 commented Aug 10, 2023

看示例代码的时候,发现示例给的代码是跑不出来的。是否存在错误?
以下是我自己测试可以运行的代码
-- Level 23

-- My Answer of Example:
-- 主查询
SELECT c.name, o.total_amount
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id
WHERE c.customer_id IN (
	-- 子查询
	SELECT customer_id 
	FROM orders
	WHERE total_amount > 200
)

====================
-- Level 24

-- 主查询
SELECT c.name, o.total_amount
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id
WHERE EXISTS (
	-- 子查询
	SELECT DISTINCT customer_id
	FROM orders
)
@wudaodao62
Copy link

customers 表中没有total_amount列,查询不出来

@stayStrong007
Copy link

是的,示例代码存在问题。外部查询中SELECT后直接跟total_amount字段是不合理的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants