当前位置:网站首页>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);运行结果

边栏推荐
- 7-5 blessing arrived
- LeetCode 1545. Find the k-th bit in the nth binary string
- Full record of ByteDance technology newcomer training: a guide to the new growth of school recruitment
- LeetCode 1558. Get the minimum number of function calls of the target array
- LeetCode 1560. The sector with the most passes on the circular track
- LeetCode 1637. The widest vertical area between two points without any point
- 汇编语言段定义
- Soft music -js find the number of times that character appears in the string - Feng Hao's blog
- 字节跳动海外技术团队再夺冠:高清视频编码已获17项第一
- LeetCode 1447. Simplest fraction
猜你喜欢

Gridhome, a static site generator that novices must know

这116名学生,用3天时间复刻了字节跳动内部真实技术项目

Cmake Express

Fdog series (VI): use QT to communicate between the client and the client through the server (less information, recommended Collection)

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

7-5 blessing arrived

Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.

Erlang installation

README. txt

字节跳动多篇论文入选 CVPR 2021,精选干货都在这里了
随机推荐
DS18B20數字溫度計系統設計
7-10 punch in strategy
Solr new core
7-5 blessing arrived
One hundred questions of image processing (1-10)
搭建flutter环境入坑集合
Mongodb在node中的使用
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
SQL快速入门
~73 other text styles
亮相Google I/O,字节跳动是这样应用Flutter的
汇编语言段定义
LeetCode 1558. Get the minimum number of function calls of the target array
LeetCode 1551. Minimum operand to make all elements in the array equal
谢邀,人在工区,刚交代码,在下字节跳动实习生
How to generate six digit verification code
LeetCode 1640. Can I connect to form an array
~81 long table
Monomer application concept
~72 horizontal and vertical alignment of text