当前位置:网站首页>Mathematical function of MySQL function summary
Mathematical function of MySQL function summary
2022-07-23 14:48:00 【Operation and maintenance home】
What is? mysql function ?
==============
The function means to return a value with a specific relationship to the input parameter value ,mysql Provides a large number of rich functions , Various functions will be often used in database management and data query and operation .
Various functions are mainly divided into the following types in terms of functions :
Mathematical functions
String function
Date and time functions
Conditional judgment function
System information function
Encryption function and other functions
This article mainly introduces the relevant use methods of mathematical functions .
What is a mathematical function ?
Mathematical functions are mainly used to deal with numerical data , The main mathematical functions include the following functions :
Absolute value function
Trigonometric functions
Sine function
cosine function
Tangent function
Cotangent function
Logarithmic function
Random functions, etc
If the function reports an error , The mathematical function will return null NULL.
Absolute value function ABS(x)
abs(x) return x The absolute value of ;
mysql> select abs(2), abs(-6.6), abs(-99), abs(3.000);
+--------+-----------+----------+------------+
| abs(2) | abs(-6.6) | abs(-99) | abs(3.000) |
+--------+-----------+----------+------------+
| 2 | 6.6 | 99 | 3.000 |
+--------+-----------+----------+------------+
1 row in set (0.00 sec)
mysql>
A function that returns pi PI()
PI() Return the PI π Value . The default display decimal places are the first 6 position .
mysql> select pi();
+----------+
| pi() |
+----------+
| 3.141593 |
+----------+
1 row in set (0.00 sec)
mysql>
Square root function SQRT(x)
SQRT(x) Returns a non negative number x The square root of .
mysql> select sqrt(9), sqrt(30), sqrt(-30);
+---------+-------------------+-----------+
| sqrt(9) | sqrt(30) | sqrt(-30) |
+---------+-------------------+-----------+
| 3 | 5.477225575051661 | NULL |
+---------+-------------------+-----------+
1 row in set (0.00 sec)
mysql>
Find the cofunction MOD(x,y)
mod(x,y) return x By y The remainder after division ,mod() Values with decimal parts can also be calculated , He returns the exact remainder after the trigger operation .
mysql> select mod(31,10), mod(31.5,3), mod(-31,10);
+------------+-------------+-------------+
| mod(31,10) | mod(31.5,3) | mod(-31,10) |
+------------+-------------+-------------+
| 1 | 1.5 | -1 |
+------------+-------------+-------------+
1 row in set (0.00 sec)
mysql>
Get the function of an integer CEIL(x)、CEILING(x) and FLOOR(x)
ceil(x) and ceiling(x) It means the same thing , Return no less than x The minimum integer value of , The return value is converted into a bigint.
mysql> select ceil(20), ceil(-3.33), ceiling(20), ceiling(-3.33);
+----------+-------------+-------------+----------------+
| ceil(20) | ceil(-3.33) | ceiling(20) | ceiling(-3.33) |
+----------+-------------+-------------+----------------+
| 20 | -3 | 20 | -3 |
+----------+-------------+-------------+----------------+
1 row in set (0.01 sec)
mysql>
floor(x) Return is no greater than x Maximum integer value ;
mysql> select floor(20), floor(-3.33);
+-----------+--------------+
| floor(20) | floor(-3.33) |
+-----------+--------------+
| 20 | -4 |
+-----------+--------------+
1 row in set (0.00 sec)
mysql>
A function to get random numbers RAND() and RAND(x)
rand(x) Returns a random floating-point value , The scope is 0~1 Between , If you specify an overall parameter x, Then this x Used as seed value , Used to generate repeat sequences .
rand Without parameters
mysql> select rand(), rand(), rand();
+--------------------+---------------------+---------------------+
| rand() | rand() | rand() |
+--------------------+---------------------+---------------------+
| 0.5348021588612368 | 0.19999561477452107 | 0.39557162802254003 |
+--------------------+---------------------+---------------------+
1 row in set (0.00 sec)
mysql>
You can see that each random value returned is different .
rand Add parameter
mysql> select rand(5), rand(5), rand();
+---------------------+---------------------+--------------------+
| rand(5) | rand(5) | rand() |
+---------------------+---------------------+--------------------+
| 0.40613597483014313 | 0.40613597483014313 | 0.3778713265227818 |
+---------------------+---------------------+--------------------+
1 row in set (0.00 sec)
mysql>
You can see from above , If you use rand(x), And x The value of is the same , Then the generated random value , It's the same , conversely , Different x, The resulting random value , Not so .
function ROUND(x)、ROUND(x,y) and TRUNCATE(x,y)
round(x) Returns the closest parameter x The integer of , Yes x Values are rounded .
mysql> select round(-2.58), round(6.2), round(9.9);
+--------------+------------+------------+
| round(-2.58) | round(6.2) | round(9.9) |
+--------------+------------+------------+
| -3 | 6 | 10 |
+--------------+------------+------------+
1 row in set (0.00 sec)
mysql>
round(x,y) Returns the closest parameter x Number of numbers , Its value is kept after the decimal point y position , if y negative , Will keep x To the left of the decimal point y position , Also use rounding .
mysql> select round(1.78, 1), round(1.99, 0), round(222.90, -1), round(222.90, -2), round(888.80, -2);
+----------------+----------------+-------------------+-------------------+-------------------+
| round(1.78, 1) | round(1.99, 0) | round(222.90, -1) | round(222.90, -2) | round(888.80, -2) |
+----------------+----------------+-------------------+-------------------+-------------------+
| 1.8 | 2 | 220 | 200 | 900 |
+----------------+----------------+-------------------+-------------------+-------------------+
1 row in set (0.00 sec)
mysql>
truncate(x,y) Returns the number after the decimal point is rounded off y Digit number x. if y The value of is 0, Then the result does not have a decimal point or a decimal part . if y Set to negative , Then cut off ( Zeroing )x The third from the left of the decimal point y All the lower values after the beginning of the bit . The way that applies here is in Mathematics Go to the tail .
mysql> select truncate(1.22,1), truncate(1.66,1), truncate(666.66, -2), truncate(666.66,0);
+------------------+------------------+----------------------+--------------------+
| truncate(1.22,1) | truncate(1.66,1) | truncate(666.66, -2) | truncate(666.66,0) |
+------------------+------------------+----------------------+--------------------+
| 1.2 | 1.6 | 600 | 666 |
+------------------+------------------+----------------------+--------------------+
1 row in set (0.00 sec)
mysql>
Symbolic function SIGN(x)
sign(x) Returns the symbol of the parameter ,x The value of is negative 、 Zero or exactly the return result corresponds to -1、0 perhaps 1.
| Number type | negative | zero | Positive numbers |
|---|---|---|---|
| return | -1 | 0 | 1 |
mysql> select sign(-19), sign(-1.11), sign(0), sign(99);
+-----------+-------------+---------+----------+
| sign(-19) | sign(-1.11) | sign(0) | sign(99) |
+-----------+-------------+---------+----------+
| -1 | -1 | 0 | 1 |
+-----------+-------------+---------+----------+
1 row in set (0.00 sec)
mysql>
Power function POW(x,y)、POWER(x,y) and EXP(x)
pow(x,y) perhaps power(x,y) The function returns x Of y The resulting value of the power .
mysql> select pow(2,2), power(2,2), pow(3,3), power(3,3), pow(-0.5,2), power(-0.5,2);
+----------+------------+----------+------------+-------------+---------------+
| pow(2,2) | power(2,2) | pow(3,3) | power(3,3) | pow(-0.5,2) | power(-0.5,2) |
+----------+------------+----------+------------+-------------+---------------+
| 4 | 4 | 27 | 27 | 0.25 | 0.25 |
+----------+------------+----------+------------+-------------+---------------+
1 row in set (0.00 sec)
mysql>
exp(x) return e Of x The value after the power
mysql> select exp(3), exp(-3), exp(0);
+--------------------+----------------------+--------+
| exp(3) | exp(-3) | exp(0) |
+--------------------+----------------------+--------+
| 20.085536923187668 | 0.049787068367863944 | 1 |
+--------------------+----------------------+--------+
1 row in set (0.00 sec)
mysql>
Logarithm function LOG(x) and LOG10(x)
log(x) return x The natural logarithm of ,x Equivalent to base e The logarithmic .
mysql> select log(3), log(-3), log(9), log(-9), log(0);
+--------------------+---------+--------------------+---------+--------+
| log(3) | log(-3) | log(9) | log(-9) | log(0) |
+--------------------+---------+--------------------+---------+--------+
| 1.0986122886681098 | NULL | 2.1972245773362196 | NULL | NULL |
+--------------------+---------+--------------------+---------+--------+
1 row in set, 3 warnings (0.00 sec)
mysql>
Since the domain of logarithm is >=0, So negative sum 0 All the returned results are null.
log10(x) return x Based on 10 The logarithmic ;
mysql> select log10(2), log10(100), log10(-100);
+--------------------+------------+-------------+
| log10(2) | log10(100) | log10(-100) |
+--------------------+------------+-------------+
| 0.3010299956639812 | 2 | NULL |
+--------------------+------------+-------------+
1 row in set, 1 warning (0.00 sec)
mysql>
It's a function of angle and radian RADIANS(x) and DEGREES(x)
radians(x) The parameter x From angle to radian ;
mysql> select radians(90), radians(100);
+--------------------+--------------------+
| radians(90) | radians(100) |
+--------------------+--------------------+
| 1.5707963267948966 | 1.7453292519943295 |
+--------------------+--------------------+
1 row in set (0.00 sec)
mysql>
degrees(x) The parameter x From radian to angle ;
mysql> select degrees(pi()), degrees(pi()/2);
+---------------+-----------------+
| degrees(pi()) | degrees(pi()/2) |
+---------------+-----------------+
| 180 | 90 |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql>
Tips :PI() Is the return of PI .
Sine function SIN(x) And anti sine functions ASIN(x)
sin(x) return x sine , among x Is the radian value ;
mysql> select sin(1), round(sin(pi()));
+--------------------+------------------+
| sin(1) | round(sin(pi())) |
+--------------------+------------------+
| 0.8414709848078965 | 0 |
+--------------------+------------------+
1 row in set (0.00 sec)
mysql>
asin(x) return x The inverse sine of , That is, the sine is x Value . if x be not in -1 To 1 Within the scope of , Then return to null.
mysql> select asin(0.8414709848078965), asin(2);
+--------------------------+---------+
| asin(0.8414709848078965) | asin(2) |
+--------------------------+---------+
| 1 | NULL |
+--------------------------+---------+
1 row in set (0.00 sec)
mysql>
function ASIN and SIN They're inverse functions to each other .
cosine function COS(x) And arccosine functions ACOS(x)
cos(x) return x The cosine of , among x Is the radian value ;
mysql> select cos(0), cos(pi()), cos(1);
+--------+-----------+--------------------+
| cos(0) | cos(pi()) | cos(1) |
+--------+-----------+--------------------+
| 1 | -1 | 0.5403023058681398 |
+--------+-----------+--------------------+
1 row in set (0.00 sec)
mysql>
acos(x) return x The arccosine of , The cosine is x Value . if x be not in -1~1 Only within , Then return to null.
mysql> select acos(1), round(acos(0.5403023058681398));
+---------+---------------------------------+
| acos(1) | round(acos(0.5403023058681398)) |
+---------+---------------------------------+
| 0 | 1 |
+---------+---------------------------------+
1 row in set (0.00 sec)
mysql>
function ACOS and COS They're inverse functions to each other .
Tangent function 、 Arctangent function and cotangent function
TAN(x) return x Tangent of , among x For a given radian value .
mysql> select tan(0.4), round(tan(pi()/4));
+--------------------+--------------------+
| tan(0.4) | round(tan(pi()/4)) |
+--------------------+--------------------+
| 0.4227932187381618 | 1 |
+--------------------+--------------------+
1 row in set (0.01 sec)
mysql>
ATAN(x) return x It's all right , That is, the tangent is x Value .
mysql> select atan(0.4227932187381618), atan(1);
+--------------------------+--------------------+
| atan(0.4227932187381618) | atan(1) |
+--------------------------+--------------------+
| 0.4 | 0.7853981633974483 |
+--------------------------+--------------------+
1 row in set (0.01 sec)
mysql>
function ATAN and TAN They're inverse functions to each other ;
COT(x) return x The cotangent of ;
mysql> select cot(0.3), 1/tan(0.3), cot(pi()/4);
+--------------------+--------------------+--------------------+
| cot(0.3) | 1/tan(0.3) | cot(pi()/4) |
+--------------------+--------------------+--------------------+
| 3.2327281437658275 | 3.2327281437658275 | 1.0000000000000002 |
+--------------------+--------------------+--------------------+
1 row in set (0.00 sec)
mysql>
function cot and TAN Reciprocal functions .
thus , In this paper, the end .
For more information, go to VX official account “ Operation and maintenance home ” , Get the latest article .
------ “ Operation and maintenance home ” ------
------ “ Operation and maintenance home ” ------
------ “ Operation and maintenance home ” ------
linux Interrupt exception ,linuxuml modeling ,linux Compile multiple source files ,linux How to update the time ,linux Paging video tutorial in ,
linux How to decompress gzip,linux Unzip a directory , How to close linux gateway ,linux Document structure diagram ,linux Improve the permission to execute ,
linux What mark is used in the document , Network security linux strengthening ,linux Check email in ,linux Change the background color ,linux Build a website under the environment .
边栏推荐
- Transferred from Yuxi information disclosure: products such as mRNA covid-19 vaccine and Jiuzhou horse tetanus immunoglobulin are expected to be on the market within this year.
- Qu'est - ce que le codage par titre?
- CSDN写文方法(二)
- Using JS to parse and execute XSS automatically
- cmake笔记
- Palindrome related topics
- 【软件测试】盘一盘工作中遇到的 Redis 异常测试
- LZ77文件压缩
- 【FLink】FLink Hash collision on user-specified ID “opt“. Most likely cause is a non-unique ID
- 关于flex布局justify-content:space-around最后一个不对齐的解决方法和为什么这样子解决是讨论
猜你喜欢

正则表达式常用语法解析

Cool code rain dynamic background registration page

10 years of software testing engineer experience, very confused

右键新建txt,新建文本文件不见了,通过添加注册表就可以解决,找来找去办法解决不了的终极办法

About flex layout justify content: the last solution to the misalignment of space around and why it is solved like this is a discussion

PKI体系快速介绍

【我可以做你的第一个项目吗?】GZIP的细节简介和模拟实现

Typora图床配置详细教程

Towhee weekly model

Zhongwang CAD professional 2022 software installation package download and installation tutorial
随机推荐
FFmpeg 2 - ffplay、ffprobe、ffmpeg 命令使用
Work notes: one time bag grabbing
It is suggested that Siyuan notes can be compatible with third-party sync disks
Palindrome related topics
Sword finger offer 46. translate numbers into strings
Qu'est - ce que le codage par titre?
Generate order number
转自玉溪信息公开:mRNA新冠疫苗、九洲马破伤风免疫球蛋白等产品有望年内上市。
利用shell脚本实现封禁扫描频率过高的ip
[applet automation minium] III. element positioning - use of wxss selector
Game (2) of 2022 Henan Mengxin League: solution to supplementary questions of Henan University of Technology
Official wechat product! Applet automation framework minium sharing Preview
JS software unloading prompt expression changes with the mouse JS special effect
【FLink】FLink Hash collision on user-specified ID “opt“. Most likely cause is a non-unique ID
Chapitre 2 requête de base et tri
第2章 基础查询与排序
Cool code rain dynamic background registration page
Ffmpeg 1 - Overview / installation
FFmpeg 1 - 概览/安装
Right click to create a new TXT. The new text file is missing. You can solve it by adding a registry. Find the ultimate solution that can't be solved