Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 除法输出中缺少小数_Sql_Casting_Decimal_Division - Fatal编程技术网

Sql 除法输出中缺少小数

Sql 除法输出中缺少小数,sql,casting,decimal,division,Sql,Casting,Decimal,Division,我是一名SQL程序员新手,但已经在这里和其他许多SQL论坛上搜索过了,不明白为什么我的简单除法脚本仍然忽略了小数。我已将所有内容都转换为十进制,但输出中仍然没有任何内容 (CAST((ABS(CAST(CAST(SUM(h4qqnb) AS DECIMAL(12,4)) - CAST(SUM(h4hdnb) AS DECIMAL(12,4))AS DECIMAL(12,4)))/CAST(SUM(h4hdnb) AS DECIMAL(12,4))) AS DECIMAL(10,2))*100)|

我是一名SQL程序员新手,但已经在这里和其他许多SQL论坛上搜索过了,不明白为什么我的简单除法脚本仍然忽略了小数。我已将所有内容都转换为十进制,但输出中仍然没有任何内容

(CAST((ABS(CAST(CAST(SUM(h4qqnb) AS DECIMAL(12,4)) - CAST(SUM(h4hdnb) AS DECIMAL(12,4))AS DECIMAL(12,4)))/CAST(SUM(h4hdnb) AS DECIMAL(12,4))) AS DECIMAL(10,2))*100)||'%' AS Count_Variance_Rate,
我错过了什么


谢谢

这是一个非常丑陋的表达,演员太多了,但本质上你所做的(只是看看最外层的演员陈述)是在说什么

CAST(someNumber as DECIMAL(10,2)
这会给你一个精确到小数点后两位的数字。然后乘以100,得到一个整数

如果您试图将一个百分比值格式化为两位小数,您可以这样做,假设h4qqnb和h4hdnb是十进制字段:

concat(cast(cast(abs(sum(h4qqnb) - sum(h4hdnb)) / sum(h4hdnb) as decimal(10, 4)) * 100 as decimal(10, 2)), '%') as Count_Variance_Rate2

位于

的工作示例请用您正在使用的RDBMs标记您的问题