ORA-00937:使用子查询时不是单组组功能

时间:2014-03-18 01:23:07

标签: sql oracle

以上错误是指子查询中的字段??子查询执行ok。但是当整个查询运行时,我得到错误并且子查询中的字段被突出显示。

select sub.admyear,        
    count(sub.age),
    case when sub.age <=18 then '1-18'
        when sub.age <=25 then '19-25'
        when sub.age <=35 then '26-35'
        when sub.age <=45 then '36-45'
        when sub.age <=55 then '46-55'
        when sub.age <=65 then '56-65'
        when sub.age <=75 then '66-75'
        when sub.age <=85 then '76-85'
        when sub.age <=95 then '86-95'
        when sub.age <=105 then '96-105'
        else 'Over 105'
        end as agerange
from (select 
    extract(year from aip.adm_date)as admyear,
    trunc((aip.adm_date-cpi.birth_date)/365,0) as age,
    aip.pt_code
from k_archipreg aip, k_archptdxreg dx,k_cpireg cpi
where aip.adm_date between '01/01/2004' and '01/01/2014'
and dx.pt_code = aip.pt_code
and cpi.pt_code = aip.pt_code
and DX.EVENT_NO = AIP.EVENT_NO
and dx.nmds_dx_code like 'J%'
)sub
group by  admyear,
     case when age >0 and age <=18 then '1-18'
        when age <=25 then '19-25'
        when age <=35 then '26-35'
        when age <=45 then '36-45'
        when age <=55 then '46-55'
        when age <=65 then '56-65'
        when age <=75 then '66-75'
        when age <=85 then '76-85'
        when age <=95 then '86-95'
        when age <=105 then '96-105'
        else 'Over 105'
        end

1 个答案:

答案 0 :(得分:0)

您是否尝试在count(sub.age)声明中加入group by