当前位置:网站首页>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);
运行结果
边栏推荐
- Simple records of business system migration from Oracle to opengauss database
- Eureka single machine construction
- Solr word segmentation analysis
- ~86m rabbit practice
- ~71 abbreviation attribute of font
- QT system learning series: 1.2 style sheet sub control lookup
- Fdog series (V): use QT to imitate QQ to realize login interface to main interface, function chapter.
- was unable to send heartbeat
- Redis standalone startup
- LeetCode 1561. The maximum number of coins you can get
猜你喜欢
The QT program compiled on CentOS lacks a MySQL driven solution
"One year after graduation, I won ACL best paper"
When it comes to Google i/o, this is how ByteDance is applied to flutter
Mp4 format details
Shell_ 01_ data processing
逻辑运算指令
ByteDance 2022 school recruitment R & D advance approval publicity meeting, students' top 10 issues
Thank you for your invitation. I'm in the work area. I just handed in the code. I'm an intern in the next ByteDance
字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
7-10 punch in strategy
随机推荐
Yao BanZhi and his team came together, and the competition experts gathered together. What fairy programming competition is this?
Solr standalone installation
~68 Icon Font introduction
~78 radial gradient
LeetCode 1562. Find the latest group of size M
LeetCode 1558. Get the minimum number of function calls of the target array
面试集锦库
The 116 students spent three days reproducing the ByteDance internal real technology project
~86m rabbit practice
~69 other ways to use icon fonts
字节跳动春招攻略:学长学姐笔经面经,还有出题人「锦囊」
[unsolved] 7-15 shout mountain
Mongodb在node中的使用
LeetCode 1636. Sort the array in ascending order by frequency
字节跳动开源GAN模型压缩框架,算力最高节省97.8%丨ICCV 2021
Typescript basic operations
谢邀,人在工区,刚交代码,在下字节跳动实习生
Error: case label `15 'not within a switch statement
~71 abbreviation attribute of font
string. How to choose h and string and CString