文章目錄
- 問題
- 案例
- 執行順序
- 使用分組解決
問題
案例
執行順序
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 … 是一個閉區間