当前位置:网站首页>MySQL之知识点(七)
MySQL之知识点(七)
2022-07-05 16:57:00 【flag:卷王!】
一、流程控制函数
流程处理函数可以根据不同的条件,执行不同的处理流程,可以在SQL语句中实现不同的条件选择。MySQL中的流程处理函数主要包括IF()、IFNULL()和CASE()函数。

IF用法:
mysql> select if(1>0,'正确','错误'),if(1<0,'正确','错误') from dual;
mysql> select if(1>0,'错误','正确'),if(1<0,'错误','正确') from dual;

二、加密与解密函数
加密与解密函数主要用于对数据库中的数据进行加密和解密处理,防止数据被他人盗取。这些函数在保证数据库安全时非常有用。

注意:在mysql8.0中,password(),encode()、decode()已经弃用。
mysql> select md5('mysql'),sha('mysql'),md5(md5('mysql')) from dual;
(注意:md5是不可逆的)

三、MySQL信息函数
MySQL中内置了一些可以查询MySQL信息函数,这些函数主要用于帮助数据库开发或运维人员更好的对数据库进行维护工作。

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

四、其他函数
MySQL中有些函数无法对其进行具体分类,但是这些函数在MySQL的开发和运维过程中也是不可忽略的。

对于format来说当n小于等于0时,则只保留整数部分
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;(而3232235876是由192乘以256的3次方,加上168乘以256的2次方,加上1乘以256,再加上100)



五、聚合函数
聚合函数(分组函数):是对一组数据进行汇总的函数,输入的是一组数据的集合,输出的是单个值。
1,常见的聚合函数
1)AVG / SUM
mysql> select avg(id),sum(id) from employees;

2)MAX / MIN(适用于数值类型、字符串类型、日期时间类型的字段或变量)
mysql> select max(id),min(id) from employees;

3)COUNT
(1)作用:计算指定字段在查询结构中出现的次数
mysql> select count(id) from employees;

(2)注意:计算指定字段出现的个数时,是不计算NULL值的。
(3)AVG=SUM / COUNT
mysql> select avg(id),sum(id)/count(id) from employees;

2,group by的使用
mysql> select id from employees group by id;
注意:
1,select中出现的非组函数的字段必须申明在group by中,反之,group by中申明的字段可以不出现在select中。
2,group by申明在from后、where后面、order by前面、limit前面
3,MySQL中group by中使用with rollup,可以得到新增一条平均值结果
mysql> select id from employees group by id with rollup;

边栏推荐
- [binary tree] insufficient nodes on the root to leaf path
- Embedded UC (UNIX System Advanced Programming) -3
- CMake教程Step3(添加库的使用要求)
- Little knowledge about C language (array and string)
- Design of electronic clock based on 51 single chip microcomputer
- Etcd build a highly available etcd cluster
- What else do you not know about new map()
- Application of threshold homomorphic encryption in privacy Computing: Interpretation
- Embedded-c Language-5
- [Jianzhi offer] 63 Maximum profit of stock
猜你喜欢

Judge whether a number is a prime number (prime number)

一个满分的项目文档是如何书写的|得物技术

Browser rendering principle and rearrangement and redrawing
In depth understanding of redis memory obsolescence strategy
Learn about MySQL transaction isolation level

Rider set the highlighted side of the selected word, remove the warning and suggest highlighting

Using C language to realize palindrome number

Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
一文了解MySQL事务隔离级别

项目引入jar从私服Nexus 拉去遇到的一个问题
随机推荐
Embedded UC (UNIX System Advanced Programming) -2
easyNmon使用汇总
張平安:加快雲上數字創新,共建產業智慧生態
Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
Zhang Ping'an: accélérer l'innovation numérique dans le cloud et construire conjointement un écosystème industriel intelligent
stirring! 2022 open atom global open source summit registration is hot!
一口气读懂 IT发展史
Detailed explanation of printf() and scanf() functions of C language
[Jianzhi offer] 63 Maximum profit of stock
Example tutorial of SQL deduplication
Deeply cultivate 5g, and smart core continues to promote 5g applications
Practical example of propeller easydl: automatic scratch recognition of industrial parts
忽米沄析:工业互联网标识解析与企业信息系统的融合应用
关于mysql中的json解析函数JSON_EXTRACT
这个17岁的黑客天才,破解了第一代iPhone!
C#实现水晶报表绑定数据并实现打印3-二维码条形码
MYSQL group by 有哪些注意事项
Embedded-c Language-4
干货!半监督预训练对话模型 SPACE
Matery主题自定义(一)黑夜模式