liyupi / sql-mother

免费的闯关式 SQL 自学教程网站,从 0 到 1 带大家掌握常用 SQL 语法,纯前端实现,简单易学~
http://sqlmother.yupi.icu
3.07k stars 352 forks source link

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

Open lischen2014 opened 11 months ago

lischen2014 commented 11 months ago

看示例代码的时候,发现示例给的代码是跑不出来的。是否存在错误? 以下是我自己测试可以运行的代码 -- 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 commented 10 months ago

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

stayStrong007 commented 8 months ago

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