评论

收藏

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

编程语言 编程语言 发布于:2021-12-31 16:39 | 阅读数:591 | 评论:0

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


关注下面的标签,发现更多相似文章