在spark sql或配置单元查询中添加范围克隆

mnemlml8  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(318)

我有一个数据

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。

uqjltbpv

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 |
+----+--------+---------+

相关问题