diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/8.31\346\225\260\346\215\256\345\272\223\345\244\215\347\263\273.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/08.31\346\225\260\346\215\256\345\272\223\345\244\215\347\263\273.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/8.31\346\225\260\346\215\256\345\272\223\345\244\215\347\263\273.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/08.31\346\225\260\346\215\256\345\272\223\345\244\215\347\263\273.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9-1er\345\233\276\347\273\230\345\210\266.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.01er\345\233\276\347\273\230\345\210\266.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9-1er\345\233\276\347\273\230\345\210\266.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.01er\345\233\276\347\273\230\345\210\266.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.5\345\217\230\351\207\217.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.05\345\217\230\351\207\217.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.5\345\217\230\351\207\217.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.05\345\217\230\351\207\217.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.6\345\276\252\347\216\257\351\200\273\350\276\221\346\216\247\345\210\266.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.06\345\276\252\347\216\257\351\200\273\350\276\221\346\216\247\345\210\266.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.6\345\276\252\347\216\257\351\200\273\350\276\221\346\216\247\345\210\266.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.06\345\276\252\347\216\257\351\200\273\350\276\221\346\216\247\345\210\266.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.7\347\254\254\344\272\224\350\212\202\350\257\276 \345\255\220\346\237\245\350\257\242.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.07\347\254\254\344\272\224\350\212\202\350\257\276 \345\255\220\346\237\245\350\257\242.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.7\347\254\254\344\272\224\350\212\202\350\257\276 \345\255\220\346\237\245\350\257\242.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.07\347\254\254\344\272\224\350\212\202\350\257\276 \345\255\220\346\237\245\350\257\242.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.14\347\264\242\345\274\225.\345\210\206\351\241\265.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.14\347\264\242\345\274\225.\345\210\206\351\241\265.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.14\347\264\242\345\274\225.\345\210\206\351\241\265.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.14\347\264\242\345\274\225.\345\210\206\351\241\265.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.15\350\247\206\345\233\276.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.15\350\247\206\345\233\276.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.15\350\247\206\345\233\276.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.15\350\247\206\345\233\276.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.19\344\272\213\345\212\241.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.19\344\272\213\345\212\241.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.19\344\272\213\345\212\241.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.19\344\272\213\345\212\241.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.20\346\270\270\346\240\207.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.20\346\270\270\346\240\207.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.20\346\270\270\346\240\207.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.20\346\270\270\346\240\207.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.21\345\207\275\346\225\260.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.21\345\207\275\346\225\260.md" similarity index 100% rename from "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/9.21\345\207\275\346\225\260.md" rename to "09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.21\345\207\275\346\225\260.md" diff --git "a/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.22\346\255\273\351\224\201.md" "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.22\346\255\273\351\224\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..66f5c4327c981e0d71125e7f6afa092c4704f449 --- /dev/null +++ "b/09\351\231\210\347\203\275\346\235\260/\347\254\224\350\256\260/09.22\346\255\273\351\224\201.md" @@ -0,0 +1,80 @@ +## 关联子查询 + +#### 同表关联一个一个对照查询 + +``` +--子查询 +select * from tb_student +where birth in (select min(birth) from tb_student group by gender) + +--关联子查询 +select * from tb_student t1 where birth =(select min(birth) from tb_student t2 + where t2.gender=t1.gender) + --=返回标量 + +--先在t1(外层查询)查询数据: gender已经查询出来了 +--在内部一行一行查询 + + +--部门工资最高的员工:部门名称,员工名称,薪水 +select * from Department d join Employee e on d.id=e.departmentId +where salary in (select max(salary) from Employee group by departmentId) + +--关联子查询 +select * from Department d join Employee e on d.id=e.departmentId +where salary = +(select max(salary) from +Employee e1 where e.departmentId=e1.departmentId) + +同表关联一个一个对照查询 +``` + +## 排序 + +``` +over +frame: rows between unbounded preceding and current row +unbounded preceding:第一行 +current row:当前行 +select score,max(score) +over (order by stuid asc rows between current row and 1 following) frame +from stuscore + +frame:rows, range +between ... and ... +unbounded preceding: 第一行 +unbounded following: 最后一行 +CURRENT ROW: 当前行 +ROWS:逻辑位置存储 RANGE:物理位置存储 + 行号 preceding: 前面几行 + 行号 following: 后面几行 +``` + +## 死锁(事务) + +#### 死锁产生的原因 + +A事务和B事务需要使用资源1,2,但是A事务占用了资源1,B事务占用了资源2,两个事务同时等待对方资源释放。 死锁是指在一组进程中的各个进程均占有不会释放的资源,但因互相申请被其他进程所占用不会释放的资源而处于的一种永久等待状态。 + +#### 防止死锁产生: + +语句保持一致 事务语句不要写太长 + +``` +--A用户 +--begin transaction: A-->语句1 +--语句1 update StuInfo set classid = 2 where StuName='黄炜杰' +--语句2 update StuInfo set classid = 2 where StuName='李雅芸' +--commit transaction + + +--B用户 +--begin transaction: B-->语句1 +--语句1: update StuInfo set classid = 2 where StuName='李雅芸' +--语句2: update StuInfo set classid = 2 where StuName='黄炜杰' +--commit transaction +``` + +事务只能整体完成 + +当一个事务无法结束时,另一个与之有关的事务就会陷入死锁,占用资源永久等待