问题描述
- oracle的“不满足”某个条件该怎么写
-
比如,我想写一个语句
insert into t1(t1.a,t1.b)
select (t2.a,t2.b) from t2 “不满足”
(t2.a=t1.a and t2.b=t1.b);
以上,求大神解惑。
解决方案
参照下这个
insert into student(sname,sage) select t2.cname,t2.cid from course t2 where not exists
(select 1 from student t1 where t1.sname = t2.cname and t1.sage = t2.cid);
解决方案二:
insert into t1(t1.a,t1.b)
select (t2.a,t2.b) from t2 not(t2.a=t1.a and t2.b=t1.b);
或者
insert into t1(t1.a,t1.b)
select (t2.a,t2.b) from t2 not(t2.a=t1.a) or not (t2.b=t1.b);
解决方案三:
create table student(
sname varchar2(10) not null,
sage number(3)
);
create table course(
cname varchar2(10) not null,
cid number(3)
);
insert into student values('YES',14);
insert into student values('YES',13);
commit;
insert into course values('YES',13);
commit;
select * from course;
select * from student;
insert into student(sname,sage) select t2.cname,t2.cid from course t2 where not exists
(select 1 from student t1 where t1.sname = t2.cname and t1.sage = t2.cid);