How to do a count on a union query

前端 未结 6 1089
谎友^
谎友^ 2020-12-28 12:32

I have the following query:

select distinct profile_id from userprofile_...

union

select distinct profile_id from productions_...

How wou

6条回答
  •  猫巷女王i
    2020-12-28 13:03

    These will not work if in one of the COUNT(*) the result is equals to 0.

    This will be better:

    SELECT SUM(total)
    FROM
    (
        select COUNT(distinct profile_id) AS total
        from userprofile_...
    
        union all
    
        select COUNT(distinct profile_id) AS total
        from productions_...
    ) x
    

提交回复
热议问题