-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
626.java
21 lines (21 loc) · 863 Bytes
/
626.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
__________________________________________________________________________________________________
# Write your MySQL query statement below
select (case
when id%2 != 0 and id != counts then id+1
when id%2 != 0 and id = counts then id
else id-1 end) as id,student
from seat, (select count(*) as counts from seat) as s order by id asc
__________________________________________________________________________________________________
SELECT
s.id,
s.student
FROM
(SELECT id - 1 AS id, student FROM seat WHERE id%2 = 0
UNION
SELECT
(CASE WHEN (cnt%2=1) AND id=cnt THEN id ELSE id + 1 END) AS id, student
FROM seat, (select count(*) as cnt from seat) as seatcnt
WHERE id%2 = 1) s
GROUP BY
s.id ASC
__________________________________________________________________________________________________