We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 69aac7b commit 0ff0253Copy full SHA for 0ff0253
MySol/Consecutive available seats.md
@@ -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
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