当前位置:网站首页>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
边栏推荐
- Thymeleaf th:with use of local variables
- 开挖财上的证券账户可以吗?安全吗?
- Two policemen were shot dead in a "safety accident" in Philadelphia, USA
- Super wow fast row, you are worth learning!
- Easyocr character recognition
- Catch all asynchronous artifact completable future
- Penetration testing methodology
- 安装配置Jenkins
- I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
- 想进阿里必须啃透的12道MySQL面试题
猜你喜欢

【华为机试真题详解】字符统计及重排

Interview shock 62: what are the precautions for group by?

Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation

Select sort and bubble sort

Change multiple file names with one click

Coding devsecops helps financial enterprises run out of digital acceleration

安装配置Jenkins

Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development

Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel

Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
随机推荐
webRTC SDP mslabel lable
Share 20 strange JS expressions and see how many correct answers you can get
用 Go 跑的更快:使用 Golang 为机器学习服务
CPU design practice - Chapter 4 practice task 3 use pre delivery technology to solve conflicts caused by related issues
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Security analysis of Web Architecture
计算中间件 Apache Linkis参数解读
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
选择排序和冒泡排序
Thymeleaf th:with use of local variables
Anaconda uses China University of science and technology source
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
Coding devsecops helps financial enterprises run out of digital acceleration
dynamic programming
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
Is the securities account given by the head teacher of qiniu school safe? Can I open an account?
The function of qualifier in C language
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
Shanghai under layoffs



























