对于正确配置此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
答案 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表格中显示的次数。