mysql不支持minus运算符
minus集合减运算符,即两个集合进行相减
举例:显示表格中第3-5行的内容
Oracle:
select *
from class01
where rownum<=5 minus (select *from class01where rownum<=2);
但是mysql可以使用join来模拟minus
mysql使用join来模拟minus的统一语法:
select table1.*
from table1 left join table2
on condition
where table2.column_name is NULL;
mysql针对本例的解答:
select table1.*
from (
select *
from class01
where rownum<=5
)table1 left join(select *from class01where rownum<=2) table2
on table1.sco=table2.sco
where table2.column_name is null;
Oracle 中没有table2.column_name,所以哪怕是用join模拟minus,在Oracle中还是要做一些改动,我是用的把table2所有字段都列出来,且均为空(不能随便选一个字段判断其为空,因为不能保证原本是否有空值,即是否有:不是因为左连接而产生的空值,而是原本在某一处就存在空值,这样数据会被误判。)
代码如下:
select table1.*
from (
select *
from class01
where rownum<=5
)table1 left join(select *from class01where rownum<=2) table2
on table1.sco=table2.sco
where table2.sname is null;