MySql數據統計

MySql數據統計

性別百分比統計

select count(1) as allData,
ifnull(sum(case when u_sex = '1' then 1 else 0 end), 0) as nanData,
ifnull(sum(case when u_sex = '2' then 1 else 0 end), 0) as nvData,
ifnull(sum(case when u_sex = '1' || u_sex = '2' then 0 else 1 end), 0) as unknownData
from t_user

在這裏插入圖片描述
在這裏插入圖片描述

客戶類型數量統計

select case c_type
when '1' then '大客戶'
when '2' then '一般客戶'
when '3' then '代理商'
end  as clientType,
count(1) as clinetTypeNum
from t_client
GROUP BY c_type

在這裏插入圖片描述
在這裏插入圖片描述

月份訂單金額統計

select 
concat(year(r_create_time), '-', month(r_create_time)) as lineTime,
IFNULL(sum(r_price), 0) as totalPrice
from t_order
where year (r_create_time)= '2019'
group by year (r_create_time), month (r_create_time)

在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章