sql 用一条语句同时查询多个表行数

2025-03-06 18:24:55
推荐回答(2个)
回答1:

你可以这样
select count(*),'a'
from table_a
union all
select count(*),'b'
from table_b
希望可以帮到你。

回答2:

有关联性就好
select a.id,count(distinct a.id),count(distinct b.id)
from a,b
where a.id=b.id
group by a.id
假设id是关联字段。