文章目录
- 问题
- 案例
- 执行顺序
- 使用分组解决
问题
案例
执行顺序
SQL 语句的执行顺序(核心步骤)
同一层级的select查询内部, 别名在整个 SELECT 计算完成前不生效
使用分组解决
select distinct s.product_id, Product.product_name from Sales sleft join Product on s.product_id = Product.product_id
where s.product_id not in
(select product_id from Sales where sale_date not between '2019-01-01' and '2019-03-31');
解释
使用 not between … and …。
between … and … 是一个闭区间