在 SQL Server 中划分 [英] Divide in SQL Server

查看:34
本文介绍了在 SQL Server 中划分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SQL Server 2005 Express 中,结果如下

In SQL Server 2005 Express, the result is below

选择 100/15 -- 结果 6

SELECT 100 / 15 --Result 6

但我想得到近似值 7(比如使用计算器)

But I wanna get approximate value 7 (like using calculator)

100/15 = 6.6666..

100 / 15 = 6.6666..

如何在 SQL Server 中实现?

How to make it in SQL Server?

推荐答案

你必须使用十进制数,例如100/15.0.如果使用整数,则结果将被解释为整数并截断为小于或等于结果的最大整数.

You have to use decimal numbers e.g. 100 / 15.0. If you use integers the result is interpreted as an integer and truncated to the largest integer that is smaller than or equal to the result.

这篇关于在 SQL Server 中划分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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