简体   繁体   English

AWS Athena:我们如何在 AWS Athena 中将 integer 值作为带有千位逗号分隔符的字符串

[英]AWS Athena: How can we get integer value as string with thousand comma separator in AWS Athena

How can we show integer numbers with thousand comma separator.我们如何用千位逗号分隔符显示 integer 数字。

So, by executing the below statement因此,通过执行以下语句

select * from 1234567890

How can we get the result as 1,234,567,890我们怎样才能得到结果为1,234,567,890

You can achieve this by casting number to string and using regex:您可以通过将数字转换为字符串并使用正则表达式来实现此目的:

with dataset(num) as (
    values (1234567890),
    (123456789),
    (12345678),
    (1234567),
    (123456),
    (12345),
    (1234),
    (123)
)

select regexp_replace(cast(num as VARCHAR), '(\d)(?=(\d\d\d)+(?!\d))', '$1,')
from dataset

Output: Output:

_col0 _col0
1,234,567,890 1,234,567,890
123,456,789 123,456,789
12,345,678 12,345,678
1,234,567 1,234,567
123,456 123,456
12,345 12,345
1,234 1,234
123 123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM