有没有 更简便的根据最大值和最小值的差值 等距分组的方法

版权声明:本文为博主原创文章,未经博主允许随机转载。 https://blog.csdn.net/mtj66/article/details/84990856

分组的小技巧,不知道有没现成的函数可以计算出来各自对应的分组

select  policy_id
 ,reserve_amount_first 
 ,min_coins_indemnity_fee
 ,max_coins_indemnity_fee
,round((reserve_amount_first-min_coins_indemnity_fee + line_space/10)/(line_space ) ,0) as level  as level # 分组从1开始
 from (select *,'1' as key from dat_month a  where pt='20181130000000' 
and reserve_amount_first is not null ) a join (
 select 
  '1' as key 
 ,min(reserve_amount_first )   min_coins_indemnity_fee 
 ,max(reserve_amount_first )   max_coins_indemnity_fee 

,(max(reserve_amount_first )  -min(reserve_amount_first ) ) /10 as line_space 
 from dat_month where pt='20181130000000' and reserve_amount_first is not null
 ) b on a.key=b.key 
 limit 100; 

猜你喜欢

转载自blog.csdn.net/mtj66/article/details/84990856