当前位置:网站首页>重要的 SQL Server 函数 - 数字函数
重要的 SQL Server 函数 - 数字函数
2022-07-28 04:16:00 【Navicat中国】
第 2 部分:数字函数
像大多数现代关系数据库产品一样,SQL Server 加载了内置函数集合。尽管某些函数在整体上非常相似,但确切的名称和签名可能有所不同。因此,我们最好复习常见 SQL 函数的 SQL Server 特定实现。在本系列的第 1 部分中,我们探讨了字符串函数。在今天的文章中,我们将继续讨论数字函数,这对生成统计信息和计算值非常有用!
ABS
这不是人们为准备去海滩而训练的腹肌。相反,ABS 是“Absolute(绝对)”的缩写。因此,ABS 函数接受一个数值作为其参数,并返回其绝对等值。用更简单的术语来说,ABS 返回给定数字(无论是正数还是负数)的正数形式。这是函数签名:
ABS(inputNumber)
在数学和统计学中,偏差(deviation)是衡量变量值与某个其他值(通常是该变量的均值或平均值)之差的量度。偏差可以是有符号的也可以是无符号的。后者是 ABS 函数将要帮你解决的。下面是一个对 ClassicModels 示例数据库的查询,该数据库显示了按城市分组的客户信用额度的有符号和无符号(绝对)偏差:

ROUND
另一个非常普遍的数字函数是 ROUND。舍入函数的实现可能会有很大不同。一些仅舍入为整数,而另一些则允许你指定要舍入的小数位数。而 SQL Server 的 ROUND 函数就能最多接受三个参数:
ROUND(number, decimals, operation)
- number:要舍入的浮点数(十进制)
- decimals:将数字舍入为的小数位数
- operation:影响舍入操作的可选参数。如果值为 0(或省略),则该函数执行常规舍入,从而 5 或更大的数字将增加至下一位数字。除 0 以外的任何其他值都会导致函数将结果截断小数位数。
将货币值舍入到小数点后两位是非常普遍的。这是我们之前的带有舍入数字的查询:

CEILING
CEILING 函数类似于 ROUND,除了它总是向上舍入到下一个整数值。因此,25.01 和 25.75 都将向上舍入到 26。这是它的语法:
CEILING(number)
让我们将 CEILING 函数应用于我们先前的查询,将舍入到最接近的整数的信用额度与通过 CEILING 筛选的信用额度进行比较:

FLOOR
FLOOR 是 CEILING 函数的反面;它总是将数字舍入到小于或等于该数字的第一个整数。对于正数,FLOOR 会简单地截断小数而不更改下一个最高整数。但是,对于负数,它的确会向下递增整数。例如,-0.5 的 FLOOR 是 -1,因为它是小于 -0.5 的第一个整数。
FLOOR(number)
在不使用 ABS 的情况下将 FLOOR 函数应用于示例查询,显示了其对正数和负数的影响:

总结
在今天的文章中,我们介绍了 SQL Server 的一些最重要的数字函数。在下一部分中,我们将研究日期函数。如果你对 Navicat for SQL Server 感兴趣,可以免费试用 14 天!
往期回顾
边栏推荐
- [untitled]
- Esp8266 WiFi module and mobile communication
- 【YOLOv5实战5】基于YOLOv5的交通标志识别系统-YOLOv5整合PyQt5
- Kingbasees Security Guide for Jincang database -- 4 data access protection
- 企业数字化建设“三不五要”原则
- 【牛客】求1+2+3+...+n
- Information system project manager (2022) - key content: Information System Security Management (20)
- 2022-7-27 顾宇佳 学习笔记
- STC timer is abnormal (how to modify the initial value, the timing time is 100ms)
- Skillfully use stack backtracking to help you quickly locate problems
猜你喜欢

Some personal understandings of openpose

Thoroughly understand the sharing function in wechat games

Fedformer MOE module

In the official online CV2 document, check the optional values of OpenCV specific parameters

Campus stray cat information recording and sharing applet source code

Security exception handling mechanism

一名合格的软件测试工程师,应该具备哪些技术能力?

ftp服务器、nfs服务器的搭建和使用

Glusterfs file is not mounted, permission: R-S

H265/hevc noun explanation -- CTU, CTB, Cu, CB, Tu, PU, TB, Pb, LCU, slice, tile, chroma, luma, I frame, B frame, P frame
随机推荐
[untitled]
【无标题】
un7.27:redis数据库常用命令。
ESP8266 WIFI 模块和手机通信
写给学生的一点建议-如何构建自己的知识体系?
Kingbasees Security Guide for Jincang database -- 6.1 introduction to strong authentication
The unsatisfied analysis of setup and hold timing is the solution
pl/sql之各参数详解(“箱子模型“)
When import is introduced, sometimes there are braces, sometimes there are no braces. How should we understand this?
ftp服务器、nfs服务器的搭建和使用
numeric_ Limits the range and related attributes of each data type learned
H. 265 web player easyplayer realizes webrtc video real-time recording function
H265/HEVC名词解释-- CTU,CTB,CU,CB,TU,PU,TB,PB,LCU,Slice,Tile,Chroma,Luma,I帧,B帧,P帧
H265/hevc noun explanation -- CTU, CTB, Cu, CB, Tu, PU, TB, Pb, LCU, slice, tile, chroma, luma, I frame, B frame, P frame
Machine learning 07: Bayesian learning
Slice切片
How does MySQL ensure high availability
jdbc使用
【YOLOv5实战5】基于YOLOv5的交通标志识别系统-YOLOv5整合PyQt5
Classification cluster analysis