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

边栏推荐
猜你喜欢

LeetCode 1552. Magnetic force between two balls

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

Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog

字节跳动技术面试官现身说法:我最想pick什么样的候选人

LeetCode 1020. Number of enclaves

Shell_ 06_ Judgment and circulation

原型链继承

Simply try the new amp model of deepfacelab (deepfake)

Simple records of business system migration from Oracle to opengauss database

~82 style of table
随机推荐
LeetCode 1984. Minimum difference in student scores
js垃圾回收机制和内存泄漏
我走过最迷的路,是字节跳动程序员的脑回路
~72 horizontal and vertical alignment of text
[unsolved]7-14 calculation diagram
Business system compatible database oracle/postgresql (opengauss) /mysql Trivia
~77 linear gradient
Record the error reason
Shell_ 05_ operator
Introduction to microservices
Shell_ 07_ Functions and regular expressions
Erlang installation
~87 animation
Conception du système de thermomètre numérique DS18B20
LeetCode 1641. Count the number of Lexicographic vowel strings
LeetCode1556. Thousand separated number
7-5 blessing arrived
LeetCode 1560. The sector with the most passes on the circular track
逻辑运算指令
was unable to send heartbeat