1、left join 結果集行數與主表查詢結果集行數一致
2、主表與輔表多關聯條件要括起來
3、對于輔表的過濾條件寫在on后面是先對輔表過濾后再與主表關聯,寫在where后面是對主表與輔表關聯后的結果集再進行過濾
4、對于主表的過濾條件寫在on后面不生效,只能寫在where后面
例如:
select t.t1,listagg(d.d2,',') as d2s from table1 tleft join table2 don (t.t1 = d.d1 and t.t2 = d.d2 and d.status in ('0','1'))where t.status='3'and t.roleid in ('roleA','roleB')and t.orgcode in ('3500')
group by t.t1d.status in ('0','1')過濾條件寫on后面是先對表d過濾縮小范圍后再與主表關聯,若寫在where后面則是對主表與輔表關聯后結果集再進行過濾。