sql MS SQL数字函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL数字函数相关的知识,希望对你有一定的参考价值。

DECLARE @num INT = -245.66,
        @num2 FLOAT = 0.25,
	@num3 FLOAT = -0.8;

SELECT ABS(@num),      -- 245
       ACOS(@num2),    -- 1.31811607165282
       ASIN(@num3),    -- -0.927295218001612
       ATAN(@num2),    -- 0.244978663126864
       CEILING(@num),  -- -245
       COS(@num2),     -- 0.968912421710645
       COT(@num2),     -- 3.91631736464594
       DEGREES(@num2), -- 14.3239448782706
       EXP(@num2),     -- 1.28402541668774
       FLOOR(@num3),   -- -1
       ROUND(@num, 1), -- -245
       SIGN(@num3),    -- -1
       SIN(@num3),     -- -0.717356090899523
       TAN(@num3)      -- -1.02963855705036

-- [AVG]
SELECT AVG(ListPrice) 
   FROM [Production].[Product];
-- Output:  437.7976	 

-- [COUNT]
SELECT COUNT(ProductID) AS Total 
   FROM [Production].[Product]; 
-- Output: 505

-- [MAX/MIN]
SELECT MAX(ListPrice), MIN(ListPrice)
    FROM [Production].[Product]; 
-- Output: 3578.27, 0.00

-- [PI]
SELECT PI(); 
-- Output: 3.14159265358979

-- [POWER]
SELECT POWER(4, 2); 
-- Output: 16

-- [RADIANS]
SELECT RADIANS(180); 
-- Output: 3

-- [RANDOM]
SELECT RAND()
-- Output: 0.210903950196124
SELECT FLOOR(RAND()*(10-5)+5); 
-- Output: 6

-- [SQRT]
SELECT SQRT(64)
-- Output: 8

-- [SUM]
SELECT SUM(ListPrice) 
   FROM [Production].[Product]; 
-- Output: 221087.79

-- [Syntax]
-- ABS(number)        absolute (positive) value of a number
-- ACOS(number)       num: -1 to 1 | arc cosine of a number
-- ASIN(number)       num: -1 to 1 | arc sine of a number
-- ATAN(number)       arc tangent of a number
-- AVG(expression)    average value of an expression
-- CEILING(number)    smallest integer value >= number
-- COS(number)        cosine of a number
-- COT(number)        cotangent of a number
-- COUNT(expression)  number of records
-- DEGREES(number)    radian value into degrees
-- EXP(number)        e raised to the power of the number
-- FLOOR(number)      largest integer value <= number
-- MAX(expression)    max value in a set of values
-- MIN(expression)    min value in a set of values
-- PI()               value of PI
-- POWER(x, y)        power of another number
-- RADIANS(number)    degree value into radians
-- RAND(seed)         random number between 0 and 1 
-- ROUND(num, decimals) rounds to a decimal places
-- SIGN(number)        sign of a number -1, 0 or 1
-- SIN(number)        sine of a number
-- SQRT(number)       square root of a number
-- SUM(expression)    sum of a set of values
-- TAN(number)        tangent of a number

以上是关于sql MS SQL数字函数的主要内容,如果未能解决你的问题,请参考以下文章

将 UDF 从 MS SQL Server 移植到 MySQL 会引发异常不正确的双精度值

sql MS SQL日期函数

sql MS SQL表值函数

sql MS SQL简单标量函数

sql MS SQL用户定义的函数语法

sql MS SQL多语句表值函数