我必须在20-24范围内的最大男性数量的国家/地区显示1行的输出。但是,sex_ratio应该显示所有范围?SQL查询简单问题子查询
SELECT age,male ,female,sex_ratio,country
FROM census.population
WHERE country<> 'Aggregated' and census.population.age='20-24'
ORDER BY male DESC FETCH FIRST 1 ROW ONLY;
应该是这样的:
--*** select age, ****
--*** total number of males, ****
--*** total number of females, ****
--*** sex_ratio,(of every age) ****
--*** country ****
--*** where the country has the highest number of ****
--*** males in the 20-24 age range ****
我的输出至今:
AGE MALE FEMALE SEX_RA COUNTRY
20-24 58275712 51794339 112.5 India
结果应该是印度,因为它有男性在20-24的最大数量范围与每个年龄的性别比(不仅仅是20-24)。 census.population.age ='总计'将提供每个年龄段的性别比例。我如何获得20至24岁男性的总年龄和全国性别比?什么是选择正在为sex_ratio工作? 我的想法是这样的,但它不起作用。
SELECT age,male ,female,sex_ratio,country
FROM census.population
WHERE country<> 'Aggregated' and census.population.age='20-24'
AND sex_ratio = (select sex_ratio from census.population
WHERE census.population.age = 'Total')
ORDER BY male DESC FETCH FIRST 1 ROW ONLY;
我的数据库
Column Name Description
REGION "WORLD"
COUNTRY "AGGREGATED" and 228 separate countries
YR "2015"
AGE "Total" and 29 separate age ranges
BOTH_SEXES AGE range number
MALE AGE range number
FEMALE AGE range number
PERCENT_BOTH_SEXES AGE range percent
PERCENT_MALE AGE range percent
PERCENT_FEMALE AGE range percent
SEX_RATIO AGE range ratio
你能否提供样本预期产出?我很难理解你想在这里实现什么。 – Shadow
我更新了我的帖子。我知道我需要一个子选择,但我卡住了。 – bastel