SQL Force 显示十进制值

标签 sql firebird

我正在使用 Firebird 数据库并正在尝试以下 sql,但每次它返回 0,而不是 0.61538(等等)。

SELECT (COUNT(myfield)/26) totalcount
FROM mytable

现在,当我删除/26 时,totalcount 会按预期返回 16。但是,当我将除以 26 的结果加回去时,结果显示为 0,但它应该显示为完整的十进制值 0.615384...有人知道为什么它不返回完整值吗?我什至尝试将它包装在 CAST((count(myfield)/26) as double) totalcount 中,但它仍然返回 0。

提前感谢您的任何建议!!!!

最佳答案

尝试:

SELECT COUNT(myfield/26.0) totalcount
FROM mytable

或者:

SELECT COUNT(CAST(myfield as double)/26) totalcount
FROM mytable

不熟悉 Firebird,但在其他实现中,您必须在除法之前将分子或分母转换/转换为小数,因为整数除法会返回整数值。

关于SQL Force 显示十进制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18987484/

相关文章:

mysql - sql 子查询返回 "Every derived table must have its own alias"

mysql - 如何在 SQL 中创建前 5 列和后 5 列?

firebird - 如何将我的本地 Firebird 数据库与另一个 Firebird 数据库同步?

firebird - 如何在 Firebird 的客户端 DML 脚本中声明/使用局部变量

macos - 使用 Delphi Firemonkey 应用程序让 firebird 在 OSX 下工作

c++ - Firebird 在 `UTF8 string converted to wstring` 上崩溃

c# - 将记录插入 sql db 后返回一个值

sql - 如何将此 SQL 查询转换为 LINQ 或 Lambda 表达式?

sql - Redshift - 过去一小时值的窗口函数

java - 连接到 Firebird 数据库时出现错误 "Insufficient memory to allocate page buffer cache"