Skip to content

Commit 0ff0253

Browse files
committed
solve question 37
1 parent 69aac7b commit 0ff0253

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
把資料庫建起來的SQL
2+
```SQL
3+
CREATE table available_seats_37 (
4+
seat_id int auto_increment,
5+
free bool,
6+
PRIMARY KEY (seat_id)
7+
);
8+
9+
INSERT INTO available_seats_37
10+
(free)
11+
VALUES
12+
(1),(0),(1),(1),(1);
13+
```
14+
15+
查詢的SQL
16+
```SQL
17+
select distinct a.seat_id from available_seats_37 as a
18+
join available_seats_37 as b
19+
where b.seat_id = a.seat_id + 1 and b.free = 1 and a.free = 1 or
20+
b.seat_id = a.seat_id - 1 and b.free = 1 and a.free = 1
21+
order by seat_id;
22+
```
23+
這是一個很醜,而且效能應該非常差的寫法。
24+
畢竟where的條件判定會每一個row都做一次,條件判定的重複性太多,多了一個`or`

0 commit comments

Comments
 (0)