当前位置:网站首页>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
边栏推荐
- Select sort and bubble sort
- Under the crisis of enterprise development, is digital transformation the future savior of enterprises
- leetcode:881. lifeboat
- Stm32+bh1750 photosensitive sensor obtains light intensity
- 通过npm 或者 yarn安装依赖时 报错 出现乱码解决方式
- 黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
- 开挖财上的证券账户可以吗?安全吗?
- Section - left closed right open
- anaconda使用中科大源
- maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
猜你喜欢

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

Mongdb learning notes

Fr exercise topic - simple question

MongDB学习笔记

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

Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发

Interpretation of Apache linkage parameters in computing middleware

计算中间件 Apache Linkis参数解读

729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」

Run faster with go: use golang to serve machine learning
随机推荐
Countermeasures of enterprise supply chain management system in UCA Era
一键更改多个文件名字
useMemo,memo,useRef等相关hooks详解
FR练习题目---综合题
Loop invariant
申请代码签名证书时如何选择合适的证书品牌?
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
Stm32+bh1750 photosensitive sensor obtains light intensity
729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "
基于TI DRV10970驱动直流无刷电机
实现一个博客系统----使用模板引擎技术
微帧科技荣获全球云计算大会“云鼎奖”!
Under the crisis of enterprise development, is digital transformation the future savior of enterprises
Fonctions communes de thymeleaf
How to choose the appropriate certificate brand when applying for code signing certificate?
easyOCR 字符识别
Long list optimized virtual scrolling
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
Two policemen were shot dead in a "safety accident" in Philadelphia, USA
Anaconda uses China University of science and technology source



























