两个表A,B
A中字段noticenum主键 。
B中字段noticenum主键,某个属性flag现在要做如下查询
如果A中noticenum与B的noticenum相等
那么将B的这条flag设置为0;如果A的noticenum在B中不存在
那么将这条记录插入到B中,并且将flag设置为1然后两个表连接查询,要求得到B中noticeno和flag flag可能是1也可能是0这样的情况一条sql怎么写啊?分不多了,希望高手能帮帮我!不胜感激~~
A中字段noticenum主键 。
B中字段noticenum主键,某个属性flag现在要做如下查询
如果A中noticenum与B的noticenum相等
那么将B的这条flag设置为0;如果A的noticenum在B中不存在
那么将这条记录插入到B中,并且将flag设置为1然后两个表连接查询,要求得到B中noticeno和flag flag可能是1也可能是0这样的情况一条sql怎么写啊?分不多了,希望高手能帮帮我!不胜感激~~
update b set flag=0 where b.noticenum in (select noticenum from a);
insert into b select noticenum,1 from a,b where a.noticenum =b.noticenum(+) and b.noticenum is null ;
open refcursor for select * from b ;
case when (select count(*) from a where a.noticenum=b.noticenum)>1 then 0 else 1 end from b
union all
select noticenum1, 1 from a where a.noticenum not in (select noticenum from b)