【发布时间】:2019-03-27 00:46:57
【问题描述】:
我遇到了以下问题:
编写一个查询,显示 2018 年加利福尼亚人的平均年龄。
平均年龄的公式如下所示。
????????????????????????????=∑(????????????+0.5)∗ ????????????????????????/∑????????????????????????
我应该得到以下结果:
average
0 38.487045
a select * from population 以这种格式给出基础数据:
fips county year age pop_female pop_male pop_total
6001 ALAMEDA 1970 0 8533 8671 17204
6001 ALAMEDA 1970 1 8151 8252 16403
6001 ALAMEDA 1970 2 7753 8015 15768
6001 ALAMEDA 1970 3 8018 8412 16430
6001 ALAMEDA 1970 4 8551 8648 17199
.....等等,从 1-100 岁到 1970-2018 年
我试过用这个:
select (sum(age + 0.5) * (pop_total) / sum(pop_total)) as
average from population group by year having year = 2018
但这给了我以下结果:
average
0.05875349176742352
我做错了什么?
【问题讨论】: