当前位置:网站首页>重要的 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 天!
往期回顾
边栏推荐
- MATLB | location and constant volume IEEE30 node implementation of distributed energy
- setup和hold timing分析不满足是解决方法
- We must do these seven things well before leaving, and it's troublesome to do one less thing.
- How much does it cost to build a self built server for ark survival evolution?
- Machine learning 07: Bayesian learning
- [MySQL database] index and transaction (often used in interview)
- 金仓数据库KingbaseES安全指南--6.2. 身份验证相关的配置文件
- [untitled]
- Slice slice
- glusterfs 文件未挂载,权限: r-s
猜你喜欢

The simulation test disconnects the server from the public network

Cookies and session

Crowdfunding platform system based on JSP & Servlet
![[coding and decoding] Huffman coding and decoding based on Matlab GUI [including Matlab source code 1976]](/img/af/27e3794f93166d8ecad9b42dafaf0f.png)
[coding and decoding] Huffman coding and decoding based on Matlab GUI [including Matlab source code 1976]

cookie与Session

It's amazing. This article completely explains the service interface testing

Power consumption: leakage power

Idea2022 change the local warehouse and configure Alibaba cloud central warehouse
![[untitled]](/img/c3/cf88f04d5aaba61d3a7464ff56ce15.png)
[untitled]

pl/sql之各参数详解(“箱子模型“)
随机推荐
H265/hevc noun explanation -- CTU, CTB, Cu, CB, Tu, PU, TB, Pb, LCU, slice, tile, chroma, luma, I frame, B frame, P frame
Security exception handling mechanism
idea2022更改本地仓库,配置阿里云中央仓库
@Requiredargsconstructor annotation
Chinese Remainder Theorem of X problem
Shell rental reptile
Virtual machine class loading mechanism
Information system project manager (2022) - key content: Knowledge Management (15)
Shanghai Telecom released public computing services and signed the action plan of "Joint Innovation Center for intelligent computing applications" with Huawei and other partners
月薪28K学员 自动化测试经验分享
Detailed explanation of pointer written test questions (C language)
Kingbasees Security Guide for Jincang database -- 4 data access protection
IPC: multi process binder Aidl user guide, including cases
Convert py file to exe executable file
ftp服务器、nfs服务器的搭建和使用
[untitled]
2022-7-27 顾宇佳 学习笔记
【day03】流程控制语句
VAE generation model (with VAE implementation MNIST code)
Go grpc: a solution of connection reset by peer