@@ -503,7 +503,18 @@ select class from courses group by class having count(distinct student) >= 5;
503
503
### 解答
504
504
505
505
``` 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
+
506
511
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;
507
518
```
508
519
509
520
@@ -520,8 +531,6 @@ select class from courses group by class having count(distinct student) >= 5;
520
531
521
532
你能不能帮她写一个 SQL query 来输出小美想要的结果呢?
522
533
523
-
524
-
525
534
** 示例:**
526
535
527
536
```
@@ -557,7 +566,31 @@ select class from courses group by class having count(distinct student) >= 5;
557
566
### 解答
558
567
559
568
``` 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
+ ```
560
580
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;
561
594
```
562
595
563
596
@@ -599,6 +632,18 @@ select class from courses group by class having count(distinct student) >= 5;
599
632
### 解答
600
633
601
634
``` 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
+
602
642
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 ;
603
648
```
604
649
0 commit comments