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)

在这里插入图片描述
在这里插入图片描述

发布了35 篇原创文章 · 获赞 27 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43948057/article/details/89879945