一个简单的sql语句.我的分真的用完了。(15分)

  • 主题发起人 devexpress
  • 开始时间
D

devexpress

Unregistered / Unconfirmed
GUEST, unregistred user!
表A
Bh, name
1 张
2 王
3 李
4 孙
5 四

从表B,通过bh和主表建立联系的。
bh sl shsl
1 20 30
1 40 40
2 30 30
2 25 25
3 10 8
4 20 20
5 40 Null

问题是:
在表A表里过滤出表B是 Sl<>shsl ,
例如
1 20 30
1 40 40 //这相等 ,但上面的不等

得出的结果是
表A
bh name
1 张
3 李
5 四

要得到这个结果该怎样写。谢谢
 
select a.* from TableA a, TableB b
where a.bh = b.bh and b.sl <> b.shsl

select b.bh,a.name from TableA a, TableB b
where a.bh = b.bh and b.sl <> b.shsl
 
select bh,name from 表A where bh not in (select bh from 表2 where sl=shsl)
 
select * From A
where A.bh in(
select distinct bh
from B
where isnull(sl,0) <> isnull(shsl,0))

用这个解决问题了。 谢谢两位。
 

Similar threads

D
回复
0
查看
726
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
756
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
765
DelphiTeacher的专栏
D
顶部