如何从SELECT与Union All SELECT中选择Distinct Count



我需要从UNION ALL查询中获得一个计数,但是到目前为止我所有的尝试都失败了,我不能让它工作。

My Initial SELECT(返回8个唯一的部门)

select distinct Department 
from ( select Department
from EFP_EmployeeFollowupManagerCommit
union all
select Department from EFP_EmploymentUser ) 
a order by Department;

我已经尝试了以下

的不同变体
SELECT COUNT(Department) as "DepCount"
FROM ( select Department
from EFP_EmployeeFollowupManagerCommit
union all
select Department
from EFP_EmploymentUser );

有人能帮忙吗?

更新!

我终于让它工作了。谢谢大家:-)

最后查询:

select count(*) from (
select distinct Department 
from ( 
select Department 
from EFP_EmployeeFollowupManagerCommit 
union all 
select Department 
from EFP_EmploymentUser ) as ddep) as depcount;

您可以尝试以下查询,它应该可以工作:

select count(*) from (select distinct Department 
from ( select Department from EFP_EmployeeFollowupManagerCommit 
union all 
select Department from EFP_EmploymentUser ));

你必须这样写:select count(distinct Department)

最新更新