PHP小丑 发表于 2021-12-31 16:39:05

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

分组的小技巧,不知道有没现成的函数可以计算出来各自对应的分组
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; 


https://blog.51cto.com/u_8649447/4868469
页: [1]
查看完整版本: 有没有 更简便的根据最大值和最小值的差值 等距分组的方法