Skip to content

Commit 3b210bd

Browse files
committed
修改 数据库.md
1 parent 08bd479 commit 3b210bd

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

LeetCode/数据库.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,18 @@ select class from courses group by class having count(distinct student) >= 5;
503503
### 解答
504504

505505
```mysql
506+
# Write your MySQL query statement below
507+
select max(Salary) as SecondHighestSalary from Employee
508+
where Salary < (select max(Salary) from Employee);
509+
```
510+
506511

512+
513+
514+
```mysql
515+
# Write your MySQL query statement below
516+
select
517+
ifnull((select distinct salary from employee order by salary desc limit 1,1),null) as SecondHighestSalary;
507518
```
508519

509520

@@ -520,8 +531,6 @@ select class from courses group by class having count(distinct student) >= 5;
520531

521532
你能不能帮她写一个 SQL query 来输出小美想要的结果呢?
522533

523-
524-
525534
**示例:**
526535

527536
```
@@ -557,7 +566,31 @@ select class from courses group by class having count(distinct student) >= 5;
557566
### 解答
558567

559568
```mysql
569+
# Write your MySQL query statement below
570+
select (
571+
case
572+
when id % 2 = 0 then id-1
573+
when id % 2 = 1 and id != (select count(*) from seat) then id+1
574+
else id
575+
end
576+
) as id,
577+
student
578+
from seat order by id;
579+
```
560580

581+
582+
583+
```mysql
584+
# Write your MySQL query statement below
585+
select * from
586+
(
587+
select id-1 as id,student from seat where mod(id,2) = 0
588+
union
589+
select id+1 as id,student from seat where mod(id,2) = 1 and id !=(select count(*) from seat)
590+
union
591+
select id,student from seat where mod(id,2) = 1 and id = (select count(*) from seat)
592+
) as temp
593+
order by id;
561594
```
562595

563596

@@ -599,6 +632,18 @@ select class from courses group by class having count(distinct student) >= 5;
599632
### 解答
600633

601634
```mysql
635+
# Write your MySQL query statement below
636+
select a.Score,(select count(distinct b.Score) from Scores as b where b.Score >= a.Score) as Rank
637+
from Scores as a
638+
order by Rank;
639+
```
640+
641+
602642

643+
```mysql
644+
# Write your MySQL query statement below
645+
select a.Score,(select count(distinct b.Score) from Scores as b where b.Score >= a.Score) as Rank
646+
from Scores as a
647+
order by Score desc;
603648
```
604649

0 commit comments

Comments
 (0)