随笔分类 -  数据库

摘要:引言 在学习mysql时,我们经常会使用explain来查看sql查询的索引等优化手段的使用情况。在使用explain时,我们可以观察到,explain的输出有一个很关键的列,它就是type属性,type表示的是扫描方式,代表 MySQL 使用了哪种索引类型,不同的索引类型的查询效率是不一样的。 在 阅读全文
posted @ 2022-05-14 21:38 Garrett_Wale 阅读(4324) 评论(1) 推荐(3) 编辑
摘要:596. 超过5名学生的课 LeetCode_MySql_596 题目描述 方法一:使用group by + where + 子查询 # Write your MySQL query statement below select c1.class from ( select class, count 阅读全文
posted @ 2021-03-09 20:28 Garrett_Wale 阅读(58) 评论(0) 推荐(0) 编辑
摘要:explain ​ explain模拟优化器执行SQL语句,在5.6以及以后的版本中,除过select,其他比如insert,update和delete均可以使用explain查看执行计划,从而知道mysql是如何处理sql语句,分析查询语句或者表结构的性能瓶颈。 作用 1、表的读取顺序 2、数据读 阅读全文
posted @ 2021-03-09 10:56 Garrett_Wale 阅读(90) 评论(0) 推荐(0) 编辑
摘要:197. 上升的温度 LeetCode_MySql_197 题目描述 代码实现 # Write your MySQL query statement below select we1.id Id from Weather we1, Weather we2 where datediff(we1.rec 阅读全文
posted @ 2021-03-06 22:45 Garrett_Wale 阅读(50) 评论(0) 推荐(0) 编辑
摘要:196. 删除重复的电子邮箱 LeetCode_MySql_196 题目描述 实现代码 # Write your MySQL query statement below # 需要找到两张表中,其他记录中具有相同邮件地址但是id更大的记录,将其删除即可 delete p1 from Person p1 阅读全文
posted @ 2021-03-06 21:22 Garrett_Wale 阅读(148) 评论(0) 推荐(0) 编辑
摘要:185. 部门工资前三高的所有员工 LeetCode_MySql_185 题目描述 方法一:使用join on # Write your MySQL query statement below select d.Name as 'Department', e1.Name as 'Employee', 阅读全文
posted @ 2021-03-03 20:20 Garrett_Wale 阅读(104) 评论(0) 推荐(0) 编辑
摘要:184. 部门工资最高的员工 LeetCode_MySql_184 题目描述 题解分析 1.首先需要使用group by找出工资最高的值 2. 然后考虑到最高工资的可能有多位,所以使用in语句找到所有符合条件的员工 3. 最外层使用连接连表查询员工所在的部门名字。 代码实现 # Write your 阅读全文
posted @ 2021-03-02 20:05 Garrett_Wale 阅读(80) 评论(0) 推荐(0) 编辑
摘要:183. 从不订购的客户 LeetCode_MySql_183 题目描述 代码实现 # Write your MySQL query statement below select Name as 'Customers' from Customers where Customers.Id not in 阅读全文
posted @ 2021-03-02 19:14 Garrett_Wale 阅读(44) 评论(0) 推荐(0) 编辑
摘要:182. 查找重复的电子邮箱 LeetCode_MySql_182 题目描述 方法一:使用笛卡尔积 # Write your MySQL query statement below select distinct t1.Email from Person t1, Person t2 where t1 阅读全文
posted @ 2021-03-02 18:28 Garrett_Wale 阅读(88) 评论(0) 推荐(0) 编辑
摘要:MySQL中的存储引擎 一、存储引擎 1、存储引擎其实就是对于数据库文件的一种存取机制,如何实现存储数据,如何为存储的数据建立索引以及如何更新,查询数据等技术实现的方法。 2、MySQL中的数据用各种不同的技术存储在文件(或内存)中,这些技术中的每一种技术都使用不同的存储机制,索引技巧,锁定水平并且 阅读全文
posted @ 2021-03-02 12:15 Garrett_Wale 阅读(117) 评论(0) 推荐(0) 编辑
摘要:181. 超过经理收入的员工 LeetCode_MySql_181 题目描述 方法一:笛卡尔积 # Write your MySQL query statement below select e1.Name as 'Employee' from Employee e1, Employee e2 wh 阅读全文
posted @ 2021-03-02 11:12 Garrett_Wale 阅读(89) 评论(0) 推荐(0) 编辑
摘要:180. 连续出现的数字 LeetCode_MySql_180 题目描述 代码实现 # Write your MySQL query statement below select distinct t1.num as ConsecutiveNums from Logs t1, Logs t2, Lo 阅读全文
posted @ 2021-03-02 10:46 Garrett_Wale 阅读(81) 评论(0) 推荐(0) 编辑
摘要:178. 分数排名 LeetCode_MySql_178 题目描述 题解分析 排名函数 DENSE_RANK()。如果使用 DENSE_RANK() 进行排名会得到:1,1,2,3,4。 RANK()。如果使用 RANK() 进行排名会得到:1,1,3,4,5。 ROW_NUMBER()。如果使用 阅读全文
posted @ 2021-03-02 10:33 Garrett_Wale 阅读(98) 评论(0) 推荐(0) 编辑
摘要:MySql_176. 第二高的薪水 LeetCode_MySql_176 题目描述 题解分析 代码实现 # Write your MySQL query statement below select( select distinct Salary from Employee order by Sal 阅读全文
posted @ 2021-03-01 22:23 Garrett_Wale 阅读(60) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示