如何对联合查询进行计数 [英] How to do a count on a union query

查看:188
本文介绍了如何对联合查询进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询:

select distinct profile_id from userprofile_...

union

select distinct profile_id from productions_...

我如何获得结果总数的计数?

How would I get the count of the total number of results?

推荐答案

如果您希望所有记录的总数,则可以执行以下操作:

If you want a total count for all records, then you would do this:

SELECT COUNT(*)
FROM
(
    select distinct profile_id 
    from userprofile_...

    union all

    select distinct profile_id 
    from productions_...
) x

这篇关于如何对联合查询进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆