当前位置:网站首页>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 lengthBe 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
边栏推荐
- mysql8.0JSON_CONTAINS的使用说明
- 申请代码签名证书时如何选择合适的证书品牌?
- 超级哇塞的快排,你值得学会!
- 如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
- C language -- structure and function
- Section - left closed right open
- 【招聘岗位】基础设施软件开发人员
- Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
- 危机重重下的企业发展,数字化转型到底是不是企业未来救星
- Fr exercise topic - simple question
猜你喜欢
Mongdb learning notes
Principle and performance analysis of lepton lossless compression
Under the crisis of enterprise development, is digital transformation the future savior of enterprises
PHP - fatal error: allowed memory size of 314572800 bytes exhausted
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
【leetcode周赛总结】LeetCode第 81 场双周赛(6.25)
Run faster with go: use golang to serve machine learning
直播预告|如何借助自动化工具落地DevOps(文末福利)
APR protocol and defense
PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用
随机推荐
Un week - end heureux
Principle and performance analysis of lepton lossless compression
Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
STM32+BH1750光敏传感器获取光照强度
How can non-technical departments participate in Devops?
注意!软件供应链安全挑战持续升级
JS bright blind your eyes date selector
选择排序和冒泡排序
漫画:程序员不是修电脑的!
[summary of leetcode weekly competition] the 81st fortnight competition of leetcode (6.25)
TS所有dom元素的类型声明
安装配置Jenkins
webRTC SDP mslabel lable
C language -- structure and function
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
启牛学堂班主任给的证券账户安全吗?能开户吗?
【NVMe2.0b 14-9】NVMe SR-IOV
leetcode:881. 救生艇
webRTC SDP mslabel lable