我有一个数据
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
我如何在火花或蜂巢中实现这一目标。
答案 0 :(得分:0)
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 |
+----+--------+---------+