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)