--方法一
select(select count(1) from 表1)
-(select count(1) from 表2)
from dual
--方法二
select a.a-b.b from
(select count(1) a from 表1) a,
(select count(1) b from 表2) b
本文介绍了两种使用SQL从两个不同的表中进行记录数量对比的方法。第一种方法利用了单条SELECT语句结合FROM DUAL来实现,而第二种方法则是通过连接两个子查询的方式完成。这些技巧对于需要快速比较不同表中记录数量的场景非常实用。
--方法一
select(select count(1) from 表1)
-(select count(1) from 表2)
from dual
--方法二
select a.a-b.b from
(select count(1) a from 表1) a,
(select count(1) b from 表2) b
2159
936

被折叠的 条评论
为什么被折叠?