SQL Force显示十进制值 [英] SQL Force show decimal values

查看:69
本文介绍了SQL Force显示十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using a Firebird database and am trying the following sql but each time it returns 0, instead of 0.61538 (etc).

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

现在,当我删除/26时,totalcount将按原样返回16.但是,当我将26除后,结果显示为0,但应显示为完整的十进制值0.615384 ...有人知道为什么它不返回完整值吗?我什至尝试将其包装在CAST((count(myfield)/26)中,以double)totalcount的形式包装,但它仍返回0.

Now when I remove the /26, the totalcount returns 16 as it should. But when I add the divided by 26 back in, the result shows as 0, but it should show as the full decimal value of 0.615384... Does anyone know why it's not returning the full value? I've even tried wrapping it in a CAST((count(myfield)/26) as double) totalcount but it still returns 0.

在此先感谢您的任何建议!!!!

Thank you in advance for any suggestions!!!!

推荐答案

尝试:

SELECT COUNT(myfield/26.0) totalcount
FROM mytable

或者:

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

不熟悉Firebird,但是在其他实现中,由于整数除法会返回整数值,因此必须在除法之前将分子或分母强制转换/转换为小数.

Not familiar with Firebird, but in other implementations you have to cast/convert either the numerator or denominator as a decimal before division, as integer division returns an integer value.

这篇关于SQL Force显示十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆