1. where and having
須要的條件 >=2 + 須要使用合計條件;sql
- 分析哪些條件,要用合計函數運算;
- where 中設立不須要合計;
- 獲得合計函數;
- 設立group by 和 having 須要的合計函數條件;
2. Join 和 Aggregate Function
合計條件 + table數量 >= 2windows
- join 的條件(join的類型和條件);
- 合計函數條件(group by / Aggregate Func)
Join + group by + Aggregate Func函數
3. 重複值
windows function / distinct / join / group by / having clause ;code
- (找重仍是去重);
- distinct, group by 和 windows Func 去重;
- 找重 : having 和 windows Func;
- 簡單粗暴 : 用window function (partial by 和 order by 排序, 而後找重或者去重)。
select * from table group by name having (count *) > 2
sql : qualify
where ---> Join ---> **qualify** ---> select
4. 找nth
windows function , max排序
- 分析需求(求第幾大,仍是第幾小);
- Windows func 和 max (partial by , order by) 排序;
- 第幾大,仍是第幾小。