大佬們求助下!


我已經把這張表按照province分組計算了每個省份用戶數情況。現在想計算每個省份用戶數占總體的百分比。不知道aql代碼怎么寫了。求助下。謝謝。
-- 各省份用戶情況
select province,count(distinct user_id) as 'user'
from t_user_id_info
group by province
order by count(distinct user_id) desc;
uj5u.com熱心網友回復:
為啥要distinct,user_id不是主鍵?
select province,count(distinct user_id) as 'user',
count(distinct user_id)/(select COUNT(distinct user_id) from t_user_id_info) as ratio
from t_user_id_info
group by province
order by count(distinct user_id) desc;
uj5u.com熱心網友回復:
額,有重復的。。再問下大佬。我咋把這個占比以百分比形式呈現再保留一位小數哦轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/268342.html
標籤:基礎類
上一篇:mysql workbench 出現如下問題,請問該如何解決?
下一篇:SQL問題
