我有一个查询,可以获得一个城市的投诉数量。从蟒蛇SQL查询中计算总和的百分比/分数
query = '''
select ComplaintType as complaint_type, City as city_name,
count(ComplaintType) complaint_count
from data
where city in ({})
group by city_name, complaint_type
order by city_name
'''.format(strs_to_args(TOP_CITIES))
ComplaintType CITY_NAME .Complain_
现在,我想创建一个列计算类型t发生在城市的投诉。它会像count(ComplaintType)/ sum(count(ComplaintType)在城市)
什么是最好的语法来完成这个?
query = '''
select ComplaintType as complaint_type, City as city_name,
count(ComplaintType)/sum(count(ComplaintType) as complaint_freq
'计数(ComplaintType)/(从数据SELECT COUNT(*))'我想。 –