当前位置:网站首页>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
边栏推荐
- CPU设计实战-第四章实践任务三用前递技术解决相关引发的冲突
- MongDB学习笔记
- 面试突击62:group by 有哪些注意事项?
- SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
- Easyocr character recognition
- CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
- 选择排序和冒泡排序
- Type declaration of all DOM elements in TS
- 危机重重下的企业发展,数字化转型到底是不是企业未来救星
- [detailed explanation of Huawei machine test] happy weekend
猜你喜欢

There is a powerful and good-looking language bird editor, which is better than typora and developed by Alibaba

Under the crisis of enterprise development, is digital transformation the future savior of enterprises

Security analysis of Web Architecture

Countermeasures of enterprise supply chain management system in UCA Era

CODING DevSecOps 助力金融企业跑出数字加速度

黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,

申请代码签名证书时如何选择合适的证书品牌?
![[learning notes] stage test 1](/img/22/ad16375d8d1510c2ec75c56403a8bf.png)
[learning notes] stage test 1

CPU设计相关笔记

Two Bi development, more than 3000 reports? How to do it?
随机推荐
Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
在Pytorch中使用Tensorboard可视化训练过程
【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !
anaconda使用中科大源
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
【C 题集】of Ⅷ
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
2022年国内正规的期货公司平台有哪些啊?方正中期怎么样?安全可靠吗?
leetcode:881. lifeboat
Thymeleaf 使用后台自定义工具类处理文本
Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
Run faster with go: use golang to serve machine learning
Microframe technology won the "cloud tripod Award" at the global Cloud Computing Conference!
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Security analysis of Web Architecture
How to choose the appropriate certificate brand when applying for code signing certificate?
mysql8.0JSON_ Instructions for using contains
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
Coding devsecops helps financial enterprises run out of digital acceleration



























