sql - 使用 Union all 收到错误

标签 sql oracle group-by

select cou_name as County_Name, count(*) as count
from sdrp15_cosd 
where sd_code in (select sd_code from sdrp15_submission_log where QA_DATE IS null)
union all
select cou_name as County_Name, count(*) 
from sdrp15_cosd 
where sd_code in (select sd_code from sdrp15_submission_log where QA_DATE IS not null)
GROUP BY COU_NAME;

我正在尝试查找县名称,对于每个县,我显示链接表显示空或非空连接列的总计数。

我收到错误:

not a single-group function

最佳答案

select cou_name as County_Name, count(*) as count
from sdrp15_cosd 
where sd_code in (select sd_code from sdrp15_submission_log where QA_DATE IS 
null)
GROUP BY COU_NAME 
union all
select cou_name as County_Name, count(*) 
from sdrp15_cosd 
where sd_code in (select sd_code from sdrp15_submission_log where QA_DATE IS     
not null)
GROUP BY COU_NAME;

关于sql - 使用 Union all 收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32355332/

相关文章:

sql - 分别计算每列的不同值

python-3.x - Pandas 有条件地组合(和求和)行

sql - MSSQL中CTE、临时表和表变量的区别

sql - 范围扫描 vs 唯一扫描 vs 跳过扫描

mysql - 在 SQL 中按范围分组

oracle - 使用IP地址: The network adapter could not establish the connection访问Oracle数据库

ruby-on-rails-3 - Rails 3 中 View 中的记录分组?

python - 使用 Pandas 为每个过滤器识别列中最接近的值

java - 在没有准备语句的 SQL 中转义字符

sql - 事务隔离级别 - 选择正确的隔离级别