当前位置:网站首页>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;
边栏推荐
- [wechat applet] read the life cycle and route jump of the applet
- 蚂蚁金服的暴富还未开始,Zoom的神话却仍在继续!
- CMake教程Step2(添加库)
- Deeply cultivate 5g, and smart core continues to promote 5g applications
- 编译libssh2报错找不到openssl
- 基于Redis实现延时队列的优化方案小结
- 張平安:加快雲上數字創新,共建產業智慧生態
- Domain name resolution, reverse domain name resolution nbtstat
- 漫画:如何实现大整数相乘?(整合版)
- 基于51单片机的电子时钟设计
猜你喜欢
winedt常用快捷键 修改快捷键latex编译按钮
The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
Learn about MySQL transaction isolation level
Judge whether a number is a prime number (prime number)
In depth understanding of redis memory obsolescence strategy
Embedded -arm (bare board development) -1
Etcd build a highly available etcd cluster
Read the basic grammar of C language in one article
First day of learning C language
随机推荐
[Jianzhi offer] 61 Shunzi in playing cards
SQL删除重复数据的实例教程
张平安:加快云上数字创新,共建产业智慧生态
【性能测试】全链路压测
Etcd build a highly available etcd cluster
启牛商学院股票开户安全吗?靠谱吗?
云安全日报220705:红帽PHP解释器发现执行任意代码漏洞,需要尽快升级
thinkphp模板的使用
Detailed explanation of printf() and scanf() functions of C language
EasyX second lesson
MySQL queries the latest qualified data rows
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
Zhang Ping'an: accélérer l'innovation numérique dans le cloud et construire conjointement un écosystème industriel intelligent
Allusions of King Xuan of Qi Dynasty
[7.7 live broadcast preview] the lecturer of "typical architecture of SaaS cloud native applications" teaches you to easily build cloud native SaaS applications. Once the problem is solved, Huawei's s
The third lesson of EasyX learning
2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
Rider 设置选中单词侧边高亮,去除警告建议高亮
thinkphp3.2.3