gpt4 book ai didi

sql - 数学表达式返回零

转载 作者:行者123 更新时间:2023-12-04 22:29:17 27 4
gpt4 key购买 nike

抱歉问了一个愚蠢的问题,但这个问题让我难住了。

SELECT 
81234 / 160000 * 100 AS Try1,
CAST((81234 / 160000 * 100) AS float) AS Try2

答案是 50.77125,但两个值都返回零。有什么问题?

谢谢,

最佳答案

尝试使用小数点。

就像是

SELECT 
81234 / 160000 * 100 AS Try1,
CAST((81234 / 160000 * 100) AS float) AS Try2,
81234. / 160000. * 100. AS Try3

SQL Fiddle DEMO

来自 / (Divide) (Transact-SQL)

If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

关于sql - 数学表达式返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17809890/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com