sql - spark sql中以百万,千,单位为单位的拆分值
问题描述
如何在spark sql中以十亿,百万,千,单位和小数分割值
目前我尝试了以下选项
千- ABS(数量)%1000000 输出:562191.7974663
单位- ABS(数量)%1000 输出:191.7974663
小数- ABS(数量)%1 输出:0.7974663 或 -0.56724
但是,我正在寻找下表中的输出。
Amount Amt_Billions Amt_Millions Amt_Thousands Amt_Units Amt_Decimals
3946562191.7974663 3000000000 946000000 562000 191 7974663
-743245613.56724 743000000 245000 613 56724
请谁能帮我计算一下。
提前致谢。
解决方案
嗯。. .
floor(amount / 1000000000) * 1000000000 as billions,
floor((amount % 1000000000) / 1000000) * 1000000 as millions,
floor((amount % 1000000) / 1000) * 1000) as thousands,
floor(amount % 1000) as units
小数是唯一棘手的。这些数字没有意义,因为 0.1、0.01、0.001 都将解析为1
. 我建议在某些单位中这样做,例如百万:
floor((amount % 1) * 1000000) as units
推荐阅读
- python - 在不使用列表、函数或字典的情况下查找第二小的数字
- azure - 如何使用 Azure SDK 创建 Azure Spot VM
- regex - 允许特殊字符,但当只有特殊字符时不允许
- node.js - 如何从 NodeJS 执行 Postgres 函数
- flutter - Flutter 从 Android 应用接收 Intent 结果
- multithreading - 请求-响应中的并发协程
- c# - 为什么我在 C# 中遇到 RSA 参数的问题
- javascript - 加载资源失败:服务器在 img 元素中加载图像时响应状态为 404(未找到)
- python - 如何使用 seaborn 修改 x 票?
- python-3.x - numpy 和 pandas 中的嵌套条件不起作用