将三个表之间的count(*)求和
Sum the count(*) of between three tables
我想对 3 个表之间的计数求和。我已经添加了三个输入字段来每次给出一个特定的日期,但我正在努力研究如何 SUM the COUNTS(*)
select count(*)
from db.table1
where call_date = ${var:call_date};
select count(*)
from db.table2
where call_date = ${var:call_date};
select count(*)
from db.table3
where call_date= ${var:call_date};
提前致谢
UNION ALL
中选。 SUM()
结果。
select sum(cnt) from
(
select count(*) cnt
from db.table1
where call_date = ${var:call_date}
UNION ALL
select count(*)
from db.table2
where call_date = ${var:call_date}
UNION ALL
select count(*)
from db.table3
where call_date= ${var:call_date}
) dt
您可以简单地将它们用作子查询,如下所示:
select (select count(*) from db.table1 where call_date = ${var:call_date})
+ (select count(*) from db.table2 where call_date = ${var:call_date})
+ (select count(*) from db.table3 where call_date= ${var:call_date})
as rslt;
我想对 3 个表之间的计数求和。我已经添加了三个输入字段来每次给出一个特定的日期,但我正在努力研究如何 SUM the COUNTS(*)
select count(*)
from db.table1
where call_date = ${var:call_date};
select count(*)
from db.table2
where call_date = ${var:call_date};
select count(*)
from db.table3
where call_date= ${var:call_date};
提前致谢
UNION ALL
中选。 SUM()
结果。
select sum(cnt) from
(
select count(*) cnt
from db.table1
where call_date = ${var:call_date}
UNION ALL
select count(*)
from db.table2
where call_date = ${var:call_date}
UNION ALL
select count(*)
from db.table3
where call_date= ${var:call_date}
) dt
您可以简单地将它们用作子查询,如下所示:
select (select count(*) from db.table1 where call_date = ${var:call_date})
+ (select count(*) from db.table2 where call_date = ${var:call_date})
+ (select count(*) from db.table3 where call_date= ${var:call_date})
as rslt;