我有一个数据
id amount 1 200 2 350 3 450 4 501
我想添加一个列来定义它的值的范围
id amount Range 1 200 100-200 2 350 300-400 3 450 400-500 4 501 500-600
我怎样才能做到这一点在Spark或Hive。
uqjltbpv1#
select id ,amount ,concat_ws ( '-' ,cast (floor ((amount-1)/100)*100 as string) ,cast (ceil (amount/100) *100 as string) ) as range from mytable ;
+----+--------+---------+ | id | amount | range | +----+--------+---------+ | 1 | 200 | 100-200 | | 2 | 350 | 300-400 | | 3 | 450 | 400-500 | | 4 | 501 | 500-600 | +----+--------+---------+
1条答案
按热度按时间uqjltbpv1#