ORA-00937的Oracle Order:不是单组组功能

时间:2013-07-04 16:15:34

标签: oracle nested-queries

对于正确配置此Oracle查询的任何帮助表示赞赏:

 WITH 
    anaq1 as 
        ( SELECT 
              POPULATION, 
              YEAR, 
              COUNTRY_OR_AREA 
              FROM POPULATIONS2 
              WHERE 
                 country_or_area = 'France' OR 
                 country_or_area = 'Brazil' 
         ) 
        select 
            COUNTRY_OR_AREA , 
            COUNT(*) AS OCCURANCES  
            from anaq1  
         ORDER BY COUNT(*) DESC 

1 个答案:

答案 0 :(得分:2)

缺少GROUP BY子句:

 WITH 
    anaq1 as 
    ( SELECT 
          POPULATION, 
          YEAR, 
          COUNTRY_OR_AREA 
          FROM POPULATIONS2 
          WHERE 
             country_or_area = 'France' OR 
             country_or_area = 'Brazil' 
     ) 
    select 
        COUNTRY_OR_AREA , 
        COUNT(*) AS OCCURANCES  
        from anaq1  
        GROUP BY COUNTRY_OR_AREA
        ORDER BY COUNT(*) DESC 

整个事情可以简化:

SELECT COUNTRY_OR_AREA, COUNT(*) AS OCCURANCES  
   FROM POPULATIONS2  
   WHERE country_or_area in ('France', 'Brazil')
   GROUP BY COUNTRY_OR_AREA
   ORDER BY COUNT(*) DESC 

这是计算国家或地区记录在population2表格中显示的次数。