当前位置:网站首页>[SQL brush questions] Day3----Special exercises for common functions that SQL must know
[SQL brush questions] Day3----Special exercises for common functions that SQL must know
2022-08-10 21:33:00 【stair jumping penguin】
博主昵称:跳楼梯企鹅
博主主页面链接:博主主页传送门博主专栏页面连接:专栏传送门--网路安全技术
创作初心:本博客的初心为与技术朋友们相互交流,每个人的技术都存在短板,博主也是一样,虚心求教,希望各位技术友给予指导.
博主座右铭:发现光,追随光,成为光,散发光;
博主研究方向:渗透测试、机器学习 ;
博主寄语:感谢各位技术友的支持,您的支持就是我前进的动力 ;Learn website jump links:Click here to learn with a blogger
目录
一、 MySQL必会的常用函数
1.MySQL数据库特点
官方定义:
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一.
MySQL是一种关系型数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性.
MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言.MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型和大型网站的开发都选择 MySQL 作为网站数据库.
特点:
(1)功能强大
MySQL 中提供了多种数据库存储引擎,各引擎各有所长,适用于不同的应用场合,用户可以选择最合适的引擎以得到最高性能,可以处理每天访问量超过数亿的高强度的搜索 Web 站点.MySQL5 支持事务、视图、存储过程、触发器等.
(2)支持跨平台
MySQL 支持至少 20 种以上的开发平台,包括 Linux、Windows、FreeBSD 、IBMAIX、AIX、FreeBSD 等.这使得在任何平台下编写的程序都可以进行移植,而不需要对程序做任何的修改.
(3)运行速度快
高速是 MySQL 的显著特性.在 MySQL 中,使用了极快的 B 树磁盘表(MyISAM)和索引压缩;通过使用优化的单扫描多连接,能够极快地实现连接;SQL 函数使用高度优化的类库实现,运行速度极快.
(4)支持面向对象
PHP 支持混合编程方式.编程方式可分为纯粹面向对象、纯粹面向过程、面句对象与面向过程混合 3 种方式.
(5)安全性高
灵活和安全的权限与密码系统,允许基本主机的验证.连接到服务器时,所有的密码传输均采用加密形式,从而保证了密码的安全.
(6)成本低
MySQL The database is open source and free of copyright restrictions,is a completely free product,用户可以直接通过网络下载,自主性及使用成本低.体积小,安装方便.历史悠久,用户使用活跃,遇到问题可以寻求帮助,易于维护.
(7)支持各种开发语言
MySQL 为各种流行的程序设计语言提供支持,为它们提供了很多的 API 函数,包括 PHP、ASP.NET、Java、Eiffel、Python、Ruby、Tcl、C、C++、Perl 语言等.
(8)数据库存储容量大
MySQL 数据库的最大有效表尺寸通常是由操作系统对文件大小的限制决定的,而不是由 MySQL 内部限制决定的.InnoDB 存储引擎将 InnoDB 表保存在一个表空间内,该表空间可由数个文件创建,表空间的最大容量为 64TB,可以轻松处理拥有上千万条记录的大型数据库.
(9)支持强大的内置函数
PHP 中提供了大量内置函数,几乎涵盖了 Web 应用开发中的所有功能.它内置了数据库连接、文件上传等功能,MySQL 支持大量的扩展库,如 MySQLi 等,可以为快速开发 Web 应用提供便利.
2.常用函数
(1)数字函数
(2)聚合函数
(3)字符串函数
(4)日期函数
(5)加密函数
(6)控制流函数
(7)格式化函数
(8)类型转化函数
(9)系统信息函数
(10)开窗函数
There are ten common functions above,We introduce them this time5种最常用
二、专项练习
1.数字函数
(1)函数
序号 | 函数 | 含义 |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
(2)刷题
题目:
代码:
SELECT
IF(age < 25 OR age IS NULL, "25岁以下", "25岁及以上") AS age_cut,
COUNT(id) AS num
FROM
user_profile
GROUP BY
age_cut
运行结果:
2.字符串函数
(1)函数
序号 | 函数 | 含义 |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
(2)刷题
题目:
代码:
SELECT device_id,gender,
case
when age>=25 then '25岁及以上'
when age between 20 and 24 then '20-24岁'
when age<24 then '20岁以下'
else '其他'
end
AS age_cut
FROM user_profile
运行结果:
3.时间函数
(1)函数
序号 | 函数 | 含义 |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
(2)刷题
题目1:
代码:
select
day(date) as day,
count(question_id) as question_cnt
from question_practice_detail
where date like '2021-08%'
group by day(date);
运行截图:
题目2:
代码:
select avg(if(b.device_id is not null,1,0)) as avg_ret
from
(select distinct device_id,date
from question_practice_detail
)a
left join
(
select distinct device_id,date_sub(date,interval 1 day) as date
from question_practice_detail
)b
on a.device_id = b.device_id and a.date = b.date
运行结果:
4.系统函数
(1)函数
序号 | 函数 | 含义 |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
5.聚合函数
(1)函数
序号 | 函数 | 含义 |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
(2)刷题
题目:
代码:
select a.university,count(b.question_id)/count(distinct(b.device_id)) as avg_answer_cnt from user_profile as a
inner join question_practice_detail as b on a.device_id =b.device_id
group by a.university
运行结果:
6.窗口函数
(1)函数
序号 | 函数 | 含义 |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
(2)刷题
题目:
代码:
Select device_id,
university,
gpa
From (
Select device_id,
university,
gpa,
row_number() over(partition by university order by gpa) as rk
From user_profile
)a
where rk = 1
运行截图:
三、小结
The third day of learning to brush questions,Let's learn and progress together
点击右边链接牛客-刷题
边栏推荐
- 【nvm】【node多版本管理工具】使用说明和踩坑(exit status 1)
- FPGA - 7系列 FPGA内部结构之Memory Resources -03- 内置纠错功能
- 2021年中国工业互联网安全大赛(福建省选拔赛) 暨首届福建省工业互联网创新大赛
- PROCEDURE :存储过程结构——《mysql 从入门到内卷再到入土》
- Uniapp编译后小程序的代码反编译一些思路
- 美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
- Future-oriented IT infrastructure management architecture - Unified IaaS
- Floating window in Auto.js
- Kubernetes Notes / Getting Started / Production Environment / Installing Kubernetes with Deployment Tools / Starting a Cluster with kubeadm / Creating a Cluster with kubeadm
- ArcMap创建镶嵌数据集、导入栅格图像并修改像元数值显示范围
猜你喜欢
Live Classroom System 08 Supplement - Tencent Cloud Object Storage and Course Classification Management
快消品行业经销商协同系统:实现经销商可视化管理,提高沟通执行效率
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
LeetCode-402-移掉K位数字
Detailed explanation and use of each module of ansible
LeetCode-498 - Diagonal Traversal
管理员必须知道的RADIUS认证服务器的部署成本
【PCBA方案】电子握力测试仪方案she‘ji
日期选择器组件(限制年份 设定仅展示的月份)
随机推荐
【PCBA方案设计】蓝牙跳绳方案
LeetCode-36-二叉搜索树与双向链表
Rider调试ASP.NET Core时报thread not gc-safe的解决方法
C. Rotation Matching
labelme-屏蔽拖拽的事件
Bedtime story | made a Bitmap and AST length system configuration
力扣215题,数组中的第K个最大元素
2021年中国工业互联网安全大赛(福建省选拔赛) 暨首届福建省工业互联网创新大赛
深度学习之 12 循环神经网络RNN2
Redis Command Manual
Getting started with kuberentes Auditing
睡前故事|用Bitmap与AST做一个配置化时长系统
地理探测器Geodetector软件的下载、应用与结果解读
[Golang]用反射让你的代码变优美
Future-oriented IT infrastructure management architecture - Unified IaaS
微擎盲盒交友变现-vp_ph打开慢优化
论文解读(g-U-Nets)《Graph U-Nets》
LeetCode-402 - Remove K digits
DDL:ALTER 修改数据库——《mysql 从入门到内卷再到入土》
2022.8.9 Mock Competition