Question

Any help with the correct formulation of this Oracle Query is appreciated:

 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 
Was it helpful?

Solution

Missing the GROUP BY clause:

 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 

The whole thing could be simplified:

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 

This is counting the number of times a country or area record shows up in the populations2 table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top