1. 程式人生 > >oracle 中的having和where,minus,union,not exists的用法

oracle 中的having和where,minus,union,not exists的用法

最近在寫sql的時候用到了上面這幾個,就整理下

union all/union 這個函式可以將倆結果集合並在一起

例:當你用到in的時候,而in只能跟1000的欄位,這個時候就可以用

where 後面的條件不允許使用聚合函式,having可以。where 是對全表進行條件篩選,返回一個結果集,having是對結果集進行篩選,也就是說where要在having的前面執行。

minus 可用於排除倆表相同的資料的id。有倆表a,b。其中相同的資料是c。select 欄位 from a minus select 欄位 from b,a where a.id=b.id

not exists和exists運用的好了,可以很輕鬆排除和查詢你想要的資料。

select * from ac01 where not exists(select * from)

得出的結果 a-c的一個結果集(從a表中剔除和b表相同資料)