当前位置:网站首页>Knowledge points of MySQL (7)
Knowledge points of MySQL (7)
2022-07-05 17:31:00 【Flag: roll king!】
One 、 Process control functions
Process processing functions can be based on different conditions , Perform different processes , Can be in SQL Statement to implement different conditional choices .MySQL The process processing functions in mainly include IF()、IFNULL() and CASE() function .

IF usage :
mysql> select if(1>0,' correct ',' error '),if(1<0,' correct ',' error ') from dual;
mysql> select if(1>0,' error ',' correct '),if(1<0,' error ',' correct ') from dual;

Two 、 Encryption and decryption functions
The encryption and decryption function is mainly used to encrypt and decrypt the data in the database , Prevent data from being stolen by others . These functions are very useful in ensuring database security .

Be careful : stay mysql8.0 in ,password(),encode()、decode() Abandoned .
mysql> select md5('mysql'),sha('mysql'),md5(md5('mysql')) from dual;
( Be careful :md5 It's irreversible )

3、 ... and 、MySQL Information functions
MySQL There are some built-in functions that can be queried MySQL Information functions , These functions are mainly used to help database developers or operation and maintenance personnel better maintain the database .

mysql> select version(),connection_id(),database(),schema(),user(),current_user() from dual;

Four 、 Other functions
MySQL Some functions in cannot classify them specifically , But these functions are MySQL In the process of development and operation and maintenance of .

about format Say when n Less than or equal to 0 when , Then only the integer part
mysql> select format(123.123,2),format(123.123,-2) from dual;
conv:
mysql> select conv(16,10,2),conv(8888,10,16),conv(null,10,2) from dual;
inet_aton,inet_ntoa:
mysql> select inet_aton('192.168.1.100'),inet_ntoa(3232235876) from dual;( and 3232235876 By 192 multiply 256 Of 3 Power , add 168 multiply 256 Of 2 Power , add 1 multiply 256, Plus 100)



5、 ... and 、 Aggregate functions
Aggregate functions ( Group function ): Is a function that summarizes a set of data , The input is a set of data , The output is a single value .
1, Common aggregate functions
1)AVG / SUM
mysql> select avg(id),sum(id) from employees;

2)MAX / MIN( For numeric types 、 String type 、 Field or variable of date time type )
mysql> select max(id),min(id) from employees;

3)COUNT
(1) effect : Calculate the number of times the specified field appears in the query structure
mysql> select count(id) from employees;

(2) Be careful : When calculating the number of occurrences of the specified field , It is not calculated NULL It's worth it .
(3)AVG=SUM / COUNT
mysql> select avg(id),sum(id)/count(id) from employees;

2,group by Use
mysql> select id from employees group by id;
Be careful :
1,select The fields of non group functions appearing in must be declared in group by in , conversely ,group by The fields declared in may not appear in select in .
2,group by The statement is in from after 、where Back 、order by front 、limit front
3,MySQL in group by Use in with rollup, You can get a new average result
mysql> select id from employees group by id with rollup;

边栏推荐
- Embedded-c Language-4
- Flask solves the problem of CORS err
- 云安全日报220705:红帽PHP解释器发现执行任意代码漏洞,需要尽快升级
- Embedded -arm (bare board development) -1
- In depth understanding of redis memory obsolescence strategy
- 普通程序员看代码,顶级程序员看趋势
- The second day of learning C language for Asian people
- Machine learning 02: model evaluation
- 这个17岁的黑客天才,破解了第一代iPhone!
- Judge whether a number is a prime number (prime number)
猜你喜欢

CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
Oracle缩表空间的完整解决实例
Learn about MySQL transaction isolation level

Embedded -arm (bare board development) -2

ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声

7. Scala class

VBA驱动SAP GUI实现办公自动化(二):判断元素是否存在

Oracle Recovery Tools ----oracle数据库恢复利器

c#图文混合,以二进制方式写入数据库

Winedt common shortcut key modify shortcut key latex compile button
随机推荐
一文了解Go语言中的函数与方法的用法
Cartoon: looking for the k-th element of an unordered array (Revised)
ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée
华为云云原生容器综合竞争力,中国第一!
漫画:有趣的海盗问题 (完整版)
33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
Embedded -arm (bare board development) -1
Tita 绩效宝:如何为年中考核做准备?
漫画:寻找股票买入卖出的最佳时机
BigDecimal除法的精度问题
得知女儿被猥亵,35岁男子将对方打至轻伤二级,法院作出不起诉决定
Domain name resolution, reverse domain name resolution nbtstat
解决“双击pdf文件,弹出”请安装evernote程序
Using C language to realize palindrome number
Cartoon: interesting [pirate] question
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
Flask solves the problem of CORS err
通过proc接口调试内核代码
Winedt common shortcut key modify shortcut key latex compile button
Rider 设置选中单词侧边高亮,去除警告建议高亮