我有一个第一个选择:
select count(id) from table_user group by idProfile
第二个选择
select count(id) from table_user
如何加入两个选择?
因为至少我需要知道有个人资料的用户部分。
例如:
预期结果:
最佳答案
对当前查询的结果进行求和
:
select nbProfileByIdProfile, sum(nbProfileByIdProfile) over (), IdProfile
from (
select count(id) nbProfileByIdProfile, IdProfile
from table_user
group by idProfile
) dt
或者,按照 @lemon 的建议 - sum 内的嵌套 count(id):
select count(id) nbProfileByIdProfile, sum(count(id)) over (), IdProfile
from table_user
group by idProfile
关于sql - 按组和总计数提取计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77067019/