我想检查哪些用户在数据库中拥有最多的记录。因此,每个用户都有一个特定的ID,并且该ID在一些表中用作参考。
有一些表包含一列UserId,例如表Exams,Answers,Questions,Classs等。是否可以对所有这些表中具有特定UserId的所有记录进行计数?
;with cte as (
select rowsCount = count(*) from A where UserId = 1
union all
select rowsCount = count(*) from B where UserId = 1
union all
select rowsCount = count(*) from C where UserId = 1
)
select sum(rowsCount) from cte
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句