为什么我在这个输出中得到Integer(我期待DECIMAL) 数据库风味是Teradata 我做错了什么?
CASE WHEN sub_e.LSD IS NOT NULL THEN CAST(baba.amt AS DECIMAL(10,2))
ELSE 0
END
-
(
SUM(
CASE
WHEN sub_e.LSD IS NOT NULL
THEN ch.actv_amt * (1 + ch.tax_percent_rate/100)
ELSE 0
END
)
)
+
CASE WHEN
sub_e.LSD IS NOT NULL THEN COALESCE(sub_e.PWC, 0)
ELSE 0
END
AS ODTS,
答案 0 :(得分:1)
如果TAX_RATE_PERCENT
未定义为 足够精确度的DECIMAL
,那么(1 + TAX_RATE_PERCENT/100)
的计算将不正确。< / p>
SELECT 6/100; -- 0 (zero - Integer division)
SELECT 6.0/100; -- 0.1 (rounding rules based on precision of numerator)
SELECT 6.00/100; -- 0.06 (expected answer)
SELECT CAST(6 AS DECIMAL(2,1))/100; -- 0.1 (rounding rules based on precision of numerator)
SELECT CAST(6 AS DECIMAL(3,2))/100; -- 0.06 (expected answer)
有关Teradata中DECIMAL数据类型行为的更多详细信息,请参阅Dnoeth的解释here。
答案 1 :(得分:0)
问题出在表格内部列的定义中,上面的查询结果是INSERT