需求:
-- 帮忙跑一下截止昨天的剩余金币的分布看一看,按1000分一段。2万分及以上算一段。
-- 主要函数 floor() 向下取整
-- floor( 积分 / 1000 + 1 )* 1000 假如 积分= 3500 则 3500/1000=3 + 1 = 4 *1000 = 4000 结果归为 4000 以下 3000以上
select
case
when Q.class_jifen > 20000 then '>= 20000' else concat(Q.class_jifen-1000,'<= 积分< ',Q.class_jifen) end as '积分段',
sum(Q.nums) as '人数'
from
(select
floor(ValidGold/1000+1) * 1000 as class_jifen,
count(distinct OwnerID) as nums
from
(select a.OwnerID,ValidGold from [10.0.0.17].jinbi_snap.dbo.Jinbi_Account a
,[10.0.0.17].jinbi_snap.dbo.jinbi_user b
where a.OwnerID=b.ID and a.type=1 and b.UserStatus=1
) A
group by floor(ValidGold/1000+1) * 1000
) Q
group by
case when Q.class_jifen > 20000 then '>= 20000'else concat(Q.class_jifen-1000,'<= 积分< ',Q.class_jifen) end
--网上资料:
--round() 遵循四舍五入把原值转化为指定小数位数,如:round(1.45,0) = 1;round(1.55,0)=2
--floor()向下舍入为指定小数位数 如:floor(1.45,0)= 1;floor(1.55,0) = 1
--ceiling()向上舍入为指定小数位数 如:ceiling(1.45,0) = 2;ceiling(1.55,0)=2