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表相同数据)

猜你喜欢

转载自blog.csdn.net/lihuihao2/article/details/80692421