首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 查询两表不相等数据,该怎么解决

2012-04-25 
sql 查询两表不相等数据select count(1) a from shipment where invoice_no金华 and supplier_noSJHD

sql 查询两表不相等数据
select count(1) a from shipment where invoice_no='金华' and supplier_no='SJHD';
   
  select count(1) b from ship where invoice_no='金华' and supplier_no='SJHD';
以上二表查询个数是相等的。
现在我要以此为条件查:
a != b 时的订单号invoice_no 列表.
invoice_no 在表shipment 是主键

[解决办法]

SQL code
select distinct invoice_nofrom shipment Awhere exists(select 1 from ship where invoice_no =A.invoice_no and supplier_no=A.supplier_no)
[解决办法]
SQL code
select * from (    select invoice_no,supplier_no,count(1) as a     from shipment group by invoice_no,supplier_no) a left join (    select invoice_no,supplier_no,count(1) as b      from ship group by invoice_no,supplier_no) b on a.invoice_no=b.invoice_no and a.supplier_no=b.supplier_no and a.a<>b.b
[解决办法]
SQL code
select distinct invoice_nofrom shipment Awhere not exists(select 1 from ship where invoice_no =A.invoice_no and supplier_no=A.supplier_no) 

热点排行