![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
mysql
三生锁链
希望这是我在计算机一步一步成长的证明!
展开
-
mysql transaction 事务 概念和用法学习
MySQL 数据处理方法:BEGIN 开始一个事务SAVEPOINT P1 建立保存点ROLLBACK 事务回滚COMMIT 事务确认#一个简单事务start transaction;insert into SC values ("9611101","D01",60);insert into SC values ("9612102","D04",89);commit ;#一个回滚事务(等于...原创 2018-06-14 08:45:27 · 835 阅读 · 0 评论 -
LeetCode #176第二高的薪水
https://leetcode-cn.com/problems/second-highest-salary/description/查询第二高的数据,思路就是先找到最大值,然后在剩下的数据里找到比最大值要小的最大值。一开始我的做法是用ifnull函数,但默认值的数据类型会改变薪水的数据类型,ifnull(Salary,null)时遇到null不输出,ifnull(Salary,'null')时遇...原创 2018-06-19 11:57:14 · 579 阅读 · 0 评论 -
LeetCode #175组合两个表
https://leetcode-cn.com/problemset/database/满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 信息。这个条件刚好满足左连接的概念,获取person表所有记录,即使address表没有对应匹配的记录。所以直接用左连接联合两个表进行查询。select FirstName,LastName,City,State from Pe...原创 2018-06-19 11:50:41 · 296 阅读 · 0 评论 -
LeetCode #196 删除重复的电子邮箱
https://leetcode-cn.com/problems/delete-duplicate-emails/description/删除p1表,p1 和 p2 表的 Email 相等并且 p1 表的 Id 比 p2 表的 Id 大delete p1 from Person p1,Person p2where p1.Email = p2.Emailand p1.Id > p2.Id...原创 2018-06-23 21:11:34 · 729 阅读 · 0 评论 -
LeetCode #184 部门工资最高的员工
https://leetcode-cn.com/problems/department-highest-salary/description/找整张表中的最高薪水的员工就比较简单子查询先找到最大薪水值select Id,Name,Salary,DepartmentId from Employeewhere Salary = (select max(Salary) from Emplo...原创 2018-06-23 20:47:48 · 994 阅读 · 1 评论 -
LeetCode #181 超过经理收入的员工
https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/description/表内查询用inner join连接as 改名e1.ManagerId = e2.Ide2表中的数据就只有e1表中ManagerId有值的行select e1.Name as Employee from Employee e1...原创 2018-06-23 17:20:18 · 384 阅读 · 0 评论 -
LeetCode #197 上升的温度
https://leetcode-cn.com/problems/rising-temperature/description/inner join 连接to_days(DATE) 将日期类型转换为公元0年0月0天到DATE的总天数select w1.Id from Weather w1 inner join Weather w2 on w1.Temperature > w2.Tempe...原创 2018-06-23 17:09:57 · 167 阅读 · 0 评论 -
LeetCode #620 有趣的电影
https://leetcode-cn.com/problems/not-boring-movies/description/mod(id,2)mysql求余函数oder by rating desc 排序,desc表示降序,默认是升序(asc)select * from cinema where mod(id,2)=1 and description != 'boring' order by r...原创 2018-06-23 14:13:03 · 231 阅读 · 0 评论 -
LeetCode #595 大的国家
https://leetcode-cn.com/problems/big-countries/description/where子查询,or 判断select name,population,area from World where area > 3000000 or population > 25000000;原创 2018-06-23 14:08:25 · 134 阅读 · 0 评论 -
LeetCode #183 从不订购的客户
https://leetcode-cn.com/problems/customers-who-never-order/description/NOT IN查找Customers 表中没有出现过在Orders 表中的CustomerId 字段的值select Name as Customers from Customers where Id not in (select CustomerId fro...原创 2018-06-23 13:45:40 · 138 阅读 · 0 评论 -
LeetCode #182 查找重复的邮箱
https://leetcode-cn.com/problems/duplicate-emails/description/直接group by分组然后count统计得到结果select Email from Person group by Email having count(*) > 1;原创 2018-06-23 13:42:48 · 292 阅读 · 0 评论 -
LeetCode #627 交换工资
https://leetcode-cn.com/problems/swap-salary/description/吐槽一下:题目应该是交换性别吧!!!条件更新,男女性别交换。用set = case,when 条件 then 修改值,end这样的语法去判断条件以及更新对应值update salary set sex = case when sex = 'm' then 'f' ...原创 2018-06-23 13:39:48 · 291 阅读 · 0 评论 -
linux mysql 数据备份与还原
备份成 sql 文件mysqldump -ujinxi -p spj > /home/spj;用 sql 文件还原数据库source /home/spj;把表数据导出到一个文本文件,逗号作为分隔符select * from STUDENT into outfile '/home/STUDENT'FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n...原创 2018-06-14 10:20:28 · 191 阅读 · 0 评论 -
mysql 基础使用教程
用户登录mysql -uroot -p以管理员账号和密码登陆,使用其他账户请把root修改为相应用户名查看数据库show databases;创建数据库create database school;进入数据库use school查看数据库中的所有表show tables;创建表create table Student( SNO cha...原创 2018-06-14 09:23:36 · 4898 阅读 · 5 评论 -
mysql grant 用户 授权 管理
mysql 中数据库管理员管理用户,相应的用户只有其所司权力,例如数据录入员拥有对某个数据库的某张表的增、查功能,数据库维护员拥有对某个数据库的所有权限,包括创建和修改表结构等。管理员创建新用户的方法create user 'newuser'@'host' identified by 'password';create user 'xin'@'localhost' identified by '...原创 2018-06-14 09:07:11 · 2061 阅读 · 0 评论 -
LeetCode #177第N高的薪水
https://leetcode-cn.com/problems/nth-highest-salary/description/看起来好像是上一道题的延伸,感觉循环一波好像也能干,但是仔细一想,万一表的元组很多呢?换个思路:先对表进行降序排序,然后查询前N个元组,最后从结果中再查询最后一个元组就是答案了。limit 函数一个参数时代表查询数量两个参数时,第一个参数代表检索偏移量(从0开始),第二个...原创 2018-06-19 12:14:30 · 608 阅读 · 0 评论