当前位置:网站首页>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;

边栏推荐
- 机器学习01:绪论
- 网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
- 张平安:加快云上数字创新,共建产业智慧生态
- Error in compiling libssh2. OpenSSL cannot be found
- CMake教程Step6(添加自定义命令和生成文件)
- Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
- C # realizes crystal report binding data and printing 3-qr code barcode
- Complete solution instance of Oracle shrink table space
- C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
- Application of threshold homomorphic encryption in privacy Computing: Interpretation
猜你喜欢
MYSQL group by 有哪些注意事项
Database design in multi tenant mode

国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」

winedt常用快捷键 修改快捷键latex编译按钮

Copy mode DMA

Etcd build a highly available etcd cluster

Judge whether a string is a full letter sentence

thinkphp3.2.3

Rider 设置选中单词侧边高亮,去除警告建议高亮
Summary of optimization scheme for implementing delay queue based on redis
随机推荐
菜刀,蚁剑,冰蝎,哥斯拉的流量特征
独立开发,不失为程序员的一条出路
Judge whether a string is a full letter sentence
MYSQL group by 有哪些注意事项
stirring! 2022 open atom global open source summit registration is hot!
Oracle缩表空间的完整解决实例
叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?
【testlink】TestLink1.9.18常见问题解决方法
Is it safe to open an account for digging wealth stocks? How is it safe to open a stock account?
What else do you not know about new map()
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
BigDecimal除法的精度问题
dried food! Semi supervised pre training dialogue model space
Is it safe for qiniu business school to open a stock account? Is it reliable?
How to write a full score project document | acquisition technology
[Web attack and Defense] WAF detection technology map
The second day of learning C language for Asian people
Deeply cultivate 5g, and smart core continues to promote 5g applications
Detailed explanation of printf() and scanf() functions of C language
NPM installation