当前位置:网站首页>Mysql---- function
Mysql---- function
2022-07-05 14:49:00 【An Li Jiu Ge】
Catalog
3、 ... and 、 Conditional judgment function
Preface
One 、 Definition of function
1、 Be similar to Java How to define
2、 With parameters
3、 Must have return value ( Line by line )
a key :java Method can have no return value , The database function must have a return value
4、 Functions can be nested in SQL In the sentence
Be careful : Stored procedures cannot
5、 Functions can be called nested round(avg())
Two 、 Common functions
1、 Date function
1) NOW(): Get the current date and time
2) DAY(): Get the day in the date
3) MONTH(): Gets the month in the date
4) YEAR(): Gets the year in the date
5) Date conversion function DATE_FORMAT()/STR_TO_DATE()DATE_FORMAT(): Convert date to string
STR_TO_DATE(): Convert string to date
2、 String function
1) UPPER()/LOWER(): Case to case
UPPER()
LOWER()
2) REPLACE(): Search and replace substrings in a string
3) SUBSTRING(): The last substring starting at a position with a specific length
Be careful : Database subscript from 1 Start
4) TRIM(): Remove the space before and after5) LENGTH(): Get string length
6) CONCAT(): Merge string functions , The return result is the string generated by the connection parameter , Parameters can be one or more
3、 Number function
1)FLOOR: Rounding down
2)CEIL: Rounding up
3)ROUND: rounding
3、 ... and 、 Conditional judgment function
1)IF(expr,v1,v2)
If expr yes TRUE Then return to v1, Otherwise return to v2Before using :
After using :
2)IFNULL(v1,v2)
If v1 Not for NULL, Then return to v1, Otherwise return to v2
3)CASE expr WHEN v1 THEN r1 [WHEN v2 THEN v2] [ELSE rn] END
If expr Is equal to a vn, Then return to the corresponding position THEN The latter result , If you don't want to wait with all the values , Then return to ELSE hinder rn
Four 、 Aggregate functions
1) SUM(): Sum up . Often with GROUP BY Use it together , It can also be used alone
2) AVG(): averaging . Often with GROUP BY Use it together , It can also be used alone
3) MAX(): For maximum . Often with GROUP BY Use it together , It can also be used alone
4) MIN(): For the minimum . Often with GROUP BY Use it together , It can also be used alone
5) COUNT(): Count the number of records . Often with GROUP BY Use it together , It can also be used alone
5、 ... and 、 Merge
1) UNION: Merge all the query results , Then remove the same records
2) UNION ALL: Merge all the query results , The same records will not be removed
![]()
Prerequisite : The number of columns in the result set is the same , The types of columns should be the same or compatible
Use scenarios : In the project statistical report module , Used to merge data
边栏推荐
- 如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
- Under the crisis of enterprise development, is digital transformation the future savior of enterprises
- 黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
- Pointer operation - C language
- Thymeleaf common functions
- FR练习题目---简单题
- CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
- Niuke: intercepting missiles
- Super wow fast row, you are worth learning!
- FR练习题目---综合题
猜你喜欢
Niuke: intercepting missiles
Two Bi development, more than 3000 reports? How to do it?
Share 20 strange JS expressions and see how many correct answers you can get
直播预告|如何借助自动化工具落地DevOps(文末福利)
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
机器学习笔记 - 灰狼优化
超级哇塞的快排,你值得学会!
MongDB学习笔记
729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "
PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用
随机推荐
想进阿里必须啃透的12道MySQL面试题
Handwriting promise and async await
Explain Vue's plan to clean up keepalive cache in time
Pointer operation - C language
CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
Fonctions communes de thymeleaf
CPU design practice - Chapter 4 practical task 2 using blocking technology to solve conflicts caused by related problems
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
安装配置Jenkins
一键更改多个文件名字
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
长列表优化虚拟滚动
[detailed explanation of Huawei machine test] character statistics and rearrangement
美国费城发生“安全事故” 2名警察遭枪杀
【leetcode周赛总结】LeetCode第 81 场双周赛(6.25)
Principle and performance analysis of lepton lossless compression
Two policemen were shot dead in a "safety accident" in Philadelphia, USA
How to choose the appropriate certificate brand when applying for code signing certificate?
anaconda使用中科大源
Reconnaissance des caractères easycr