sql查询两个表中满足某些条件的数据总数
发布网友
发布时间:2022-04-11 15:19
我来回答
共5个回答
热心网友
时间:2022-04-11 16:49
假设两张表分别为TAB1,TAB2:
SELECT SUM(CNT) FROM (
SELECT COUNT(1) CNT FROM TAB1 WHERE 满足条件A,B,C
UNION ALL
SELECT COUNT(1) CNT FROM TAB2 WHERE 满足条件A,B,C)
热心网友
时间:2022-04-11 18:07
如果字段一样的话,可以用union all,即
select * from 表1 where A,B,C
union all
select * from 表2 where A,B,C
热心网友
时间:2022-04-11 19:41
select
(select count(*) from t1 where ...)
+
(select count(*) from t2 where ...)
热心网友
时间:2022-04-11 21:33
select COUNT(字段A) from TABLE1 where A AND B AND C
union al
lselect COUNT(字段B) from TABLE2 where A AND B AND C