例如:
num result
---------------------
10 10
100 100
1000 1k
10000 10k
100000 100k
1000000 1M
10000000 10M
100000000 100M
1000000000 1000M
答案 0 :(得分:0)
select num,
case
when num / 1000000 >= 1 then cast(cast(num / 1000000 as varchar(10)) + 'M' as varchar(10))
when num / 1000 >= 1 then cast(cast(num / 1000 as varchar(10)) + 'K' as varchar(10))
else cast(num as varchar(10)) end as result
from table
输出:
+------------+--------+
| num | result |
+------------+--------+
| 10 | 10 |
| 100 | 100 |
| 1000 | 1K |
| 10000 | 10K |
| 100000 | 100K |
| 1000000 | 1M |
| 10000000 | 10M |
| 100000000 | 100M |
| 1000000000 | 1000M |
+------------+--------+