我有一個查詢,可以獲得一個城市的投訴數量。從蟒蛇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(*))'我想。 –