select b.BMBH,b.RYBH from b where b.BMBH,b.RYBH not in ( select b.BMBH,RYBH from a,b where b.BMBH = a.BMBH and b.RYBH = a.RYBH) 是这个意思么?
select bmbh,rymc from (select bmbh,rymc,'a' as c from a union select bmbh,rymc,'b' as c from a) group by bmbh,rymc having(count(*)) = 1 ; 这样,不好意思啊,刚想出来.
感觉你写的SQL和你的需求不是1回事啊! 用他写的啊! twenty_three(god is a girl) ( ) 信誉:100 Blog 加为好友 2007-04-16 15:09:50 得分: 0
twenty_three(god is a girl)他写的不行啊,语法就有错误啊.
select b.BMBH,b.RYBH from b where not exists( select b.BMBH,RYBH from a,b where b.BMBH = a.BMBH and b.RYBH = a.RYBH) 要是不行就笨点的方法 select b.BMBH,b.RYBH from b where b.BMBH not in ( select b.BMBH from a,b where b.BMBH = a.BMBH and b.RYBH = a.RYBH) and b.RYBH not in ( select b.BMBH from a,b where b.BMBH = a.BMBH and b.RYBH = a.RYBH)
select bmbh,rymc from b where bmbh||rymc not in (select bmbh||rymc from a)
select * from test minus select * from test2;
有这么麻烦吗?如下不是很简单吗? SELECT * FROM b WHERE (bmbh,rymc) NOT IN(SELECT bmbh,rymc FROM a)
select bmbh,rybh from a minus select bmbh,rhbh from b
where not exists (select BMBH from b where a.BMBH=b.BMBH)
or not exists (select RYBH from b where a.RYBH=b.RYBH)
你先试下这个SQL
BMBH RYMC
---------- ----------
001 001
002 002
003 003
004 004
005 005
表B的数据是
BMBH RYMC
---------- ----------
001 001
002 002
003 003
004 004
005 005
001 002
002 003
003 004
004 005
005 006
想把B表中最后五行的数据查出来啊.
(select bmbh,rymc from test1
union
select bmbh,rymc from test2)
group by bmbh,rymc
having(count(*)) = 1
;
这样也不可以.
where b.BMBH,b.RYBH not in (
select b.BMBH,RYBH from a,b
where b.BMBH = a.BMBH
and b.RYBH = a.RYBH)
是这个意思么?
(select bmbh,rymc,'a' as c from a
union
select bmbh,rymc,'b' as c from a)
group by bmbh,rymc
having(count(*)) = 1
;
这样,不好意思啊,刚想出来.
用他写的啊!
twenty_three(god is a girl) ( ) 信誉:100 Blog 加为好友 2007-04-16 15:09:50 得分: 0
where not exists(
select b.BMBH,RYBH from a,b
where b.BMBH = a.BMBH
and b.RYBH = a.RYBH)
要是不行就笨点的方法
select b.BMBH,b.RYBH from b
where b.BMBH not in (
select b.BMBH from a,b
where b.BMBH = a.BMBH
and b.RYBH = a.RYBH)
and b.RYBH not in (
select b.BMBH from a,b
where b.BMBH = a.BMBH
and b.RYBH = a.RYBH)
where bmbh||rymc not in
(select bmbh||rymc from a)
minus
select * from test2;
SELECT * FROM b WHERE (bmbh,rymc) NOT IN(SELECT bmbh,rymc FROM a)
minus
select bmbh,rhbh from b
刚学会的