Rya*_*ett 2 rounding sqldatatypes snowflake-cloud-data-platform
我有一个数字数据列,其中包含空值、破折号和逗号。我想删除全部并替换为 0.00。我还有一些数字是 11.4 而不是 11.40。我该如何解决?还有一些 nvl 或 round 添加逗号回来。
我尝试了一轮,我尝试做 ;;decimal(20,2),我尝试替换为 0.00。似乎什么都不起作用。
round(nvl(replace(replace(aum_total,'-',0),',',''),0)) as aum_total
Run Code Online (Sandbox Code Playgroud)
因此,从猜测的意图来看,将破折号转换为零是没有意义的。
我假设要删除数千个昏迷点,因此需要通过格式化通过TO_CHAR将其添加回来。
尾随零也是一种格式设置。
select
column1 as aum_total
,translate(aum_total, '-', '0') as t1
,replace(t1, ',', '') as r1
,zeroifnull(r1) as z1
,to_number(z1, 20, 2) as n1
,to_char(n1, '9,999,999.00') as result
from values
(null),
('1-7'),
('1,8'),
('11.4'),
('11.40'),
('11.400'),
('11.1234'),
('1,234.567');
Run Code Online (Sandbox Code Playgroud)
给出:
| 总资产管理规模 | T1 | R1 | Z1 | N1 | 结果 |
|---|---|---|---|---|---|
| 无效的 | 无效的 | 无效的 | 0 | 0 | 0.00 |
| 1-7 | 107 | 107 | 107 | 107 | 107.00 |
| 1,8 | 1,8 | 18 | 18 | 18 | 18:00 |
| 11.4 | 11.4 | 11.4 | 11.4 | 11.4 | 11.40 |
| 11.4 | 11.4 | 11.4 | 11.4 | 11.4 | 11.40 |
| 11.4 | 11.4 | 11.4 | 11.4 | 11.4 | 11.40 |
| 11.1234 | 11.1234 | 11.1234 | 11.1234 | 11.12 | 11.12 |
| 1,234.567 | 1,234.567 | 1234.567 | 1,234.567 | 1,234.57 | 1,234.57 |
进一步考虑这一点,我现在假设您的意思是您想要用零替换一个只有破折号的字符串,因为这是标准会计,而不是所有破折号,因此不会弄乱负数,因此交换到 regexp_replace,并且演员阵容似乎也可以跳过!
select
column1 as aum_total
,trim(aum_total) as t1
,regexp_replace(t1, '^-$', '0') as r1
,replace(r1, ',', '') as r2
,zeroifnull(r2) as z1
,to_char(z1, '9,999,999.00') as result
from values
(null),
(' - '),
(' -10.123 '),
('-'),
('-10.123'),
('1,8'),
('11.4'),
('11.40'),
('11.400'),
('11.1234'),
('1,234.567');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3365 次 |
| 最近记录: |