开发者

In SQL how can I get a mathematical expression to give me a double instead of a truncated int?

I am performing some math in an SQL select statement but the number is always truncated to an int. How can I make it give me a double/float value?

Example:

select top 10 id, (select COUNT(*) from table1 / 100) from tab开发者_Python百科le2

If the value was 92.738 I just get 92


You are encountering integer division. You need to ensure one of the operands is not an integer. e.g. as below.

select top 10 id, (select COUNT(*) / 100.0 from table1) from table2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜