我有一张年龄多年的人数据表。我想使用SQL来计算我的表中三个或更多折叠类别的年龄段的人的百分比,例如18 - 29,30 - 39,40 - 49等。
基本上,我希望我的桌子看起来像这样:
import requests
response = requests.get("http://www.example.com")
print(response.status_code)
print(response.reason)
这是我的问题:
Count | AgeCat | percent
400 | 50 and older | .40
300 | 35 to 49 | .30
300 | Under 35 | .30
上面的窗口功能仅在我将年龄限制为两类崩溃(超过/低于50)时才有效。
答案 0 :(得分:0)
这是您的查询:
<ComboBox
ItemsSource="{Binding WeekDays}"
DisplayMemberPath="WeekDayLong"
SelectedValuePath="WeekDayLong"
SelectedValue="{Binding SelectedWeekDay}"
SelectedIndex="{Binding SelectedIndex}">
</ComboBox>
<TextBox
Text="{Binding SelectedWeekDay.WeekDayLong}">
</TextBox>
这应该有效。但是,我会把它写成:
select count(*),
(case when age >= 50 then '50 and older'
when age < 50 and age >= 35 then '35 to 49'
else 'Under 35'
end) as AgeCat,
count(*)/sum(count(*)) over (partition by '') as percent
from mydata
group by 2;