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)