怎么让sql查询的两个结果,对比只显示结果不同的。

问题相关代码

表格1查询:select mbl from passinfo where orderid='443140' and toolsindex='60'
表格2查询:select mbl from indata where orderid='443140'

运行结果内容

表格1查询显示列:mbl数量有2621个
表格2查询显示列:mbl数量有16608个

我想要达到的结果

对比表1和表格2,只显示表格1未包含的mbl个数13987。

img

img

select mbl from passinfo where orderid='443140' and toolsindex!='60'

或者

select mbl from indata where orderid='443140' and mbl not in(
  select mbl from passinfo where orderid='443140' and toolsindex='60'
)

表格2语句
except
表格1语句

最简单的方式,用except

select mbl from indata where orderid='443140'
except
select mbl from passinfo where orderid='443140' and toolsindex='60'

或者用exists

select mbl from indata a where orderid='443140' and 
not exists (select 1 from  passinfo b where b.orderid='443140' and b.toolsindex='60' and a.mbl=b.mbl)

或者用 in,上面有人贴了代码了

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

只要第一条语句,把条件改为!=60就可以了

select mbl from passinfo where orderid='443140' and toolsindex != '60'