当前位置:网站首页>MySQL数字函数
MySQL数字函数
2022-07-06 09:30:00 【My71】
下文中使用到的数据库,可参考 创建练习数据库
求绝对值
函数:ABS(number)
指令
SELECT ABS(10) AS 取绝对值, ABS(-10) AS 取绝对值;运行结果

求平均值
函数:AVG(字段)
需求:计算 xs_kc 表中学号为 081101 的学生所有课程的平均成绩。
指令
select 学号,课程号,avg(成绩) as 平均成绩 from xs_kc where 学号="081101"运行结果

求和
函数:SUM()
需求:计算 xs_kc 表中所有学生的成绩和。
指令
select sum(成绩) as 总成绩 from xs_kc运行结果

求幂
函数:POW(x,y)
说明:返回 x 的 y 次方
指令
SELECT POW(2,3),POW(3,2);运行结果

求余
函数:MOD(x,y)
说明:返回值为 x 除以 y 的余数。
指令
SELECT MOD(10,3),MOD(10,5);运行结果

整除
语法:x DIV y
说明:返回 x 除以 y 结果的整数部分,不进行四舍五入。
指令
SELECT 10 DIV 3,5 DIV 2;运行结果

向上取整
函数:CEIL()
说明:该函数会返回一个大于等于这个数的最小整数。
指令
select CEIL(1.5);运行结果

向下取整
函数:FLOOR()
说明:该函数会返回一个小于等于这个数的最小整数。
指令
select FLOOR(1.5);运行结果

四舍五入取整
函数:ROUND()
指令
SELECT ROUND(1.23),ROUND(1.57);运行结果

保留小数点后 n 位
函数:TRUNCATE(x,y)
说明:x 是要处理的小数,y 是保留的位数,不会进行四舍五入。
指令
SELECT TRUNCATE(3.1415926,2),TRUNCATE(3.1415926,4);运行结果

返回字段中最大值
函数:MAX()
需求:找出 xs_kc 表中成绩最高的记录。
需求
select 学号,课程号,max(成绩) as 成绩最大值 from xs_kc;运行结果

返回字段中最小值
函数:MIN()
需求:找出 xs_kc 表中成绩最低的记录。
指令
select 学号,课程号,min(成绩) as 成绩最大值 from xs_kc;运行结果

角度转弧度
函数:RADIANS()
指令
SELECT RADIANS(60),RADIANS(90);运行结果

弧度转角度
函数:DEGREES()
指令
SELECT DEGREES(1.0471975511965976),DEGREES(1.5707963267948966);运行结果

边栏推荐
- Mongodb在node中的使用
- Train 100 pictures for 1 hour, and the style of the photos changes at will. There is a demo at the end of the article | siggraph 2021
- Monomer application concept
- LeetCode 1561. The maximum number of coins you can get
- DS18B20數字溫度計系統設計
- Codeforces Global Round 19
- The 116 students spent three days reproducing the ByteDance internal real technology project
- ~71 abbreviation attribute of font
- Typescript basic operations
- Fdog series (VI): use QT to communicate between the client and the client through the server (less information, recommended Collection)
猜你喜欢

字节跳动技术新人培训全记录:校招萌新成长指南

Shell_ 04_ Shell script

Mp4 format details

One hundred questions of image processing (11-20)

这群程序员中的「广告狂人」,把抖音广告做成了AR游戏

The 116 students spent three days reproducing the ByteDance internal real technology project

我走过最迷的路,是字节跳动程序员的脑回路

Detailed explanation of FLV format

Shell_ 01_ data processing

~87 animation
随机推荐
[graduation project] QT from introduction to practice: realize imitation of QQ communication, which is also the last blog post in school.
LeetCode 1640. Can I connect to form an array
JS encapsulates the method of array inversion -- Feng Hao's blog
~87 animation
LeetCode 1584. Minimum cost of connecting all points
字节跳动开源GAN模型压缩框架,算力最高节省97.8%丨ICCV 2021
Mongodb在node中的使用
Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.
服务器端渲染(SSR)和客户端渲染(CSR)的区别
Full record of ByteDance technology newcomer training: a guide to the new growth of school recruitment
LeetCode 1638. Count the number of substrings with only one character difference
Two weeks' experience of intermediate software designer in the crash soft exam
Solr word segmentation analysis
LeetCode 1641. Count the number of Lexicographic vowel strings
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
Erlang installation
汇编课后作业
我走过最迷的路,是字节跳动程序员的脑回路
[unsolved] 7-15 shout mountain
7-10 punch in strategy