回答編集履歴
1
参考
test
CHANGED
@@ -1,3 +1,31 @@
|
|
1
1
|
見た感じ、なにかのランク付けじゃないですか?
|
2
2
|
|
3
3
|
id順に連番をつけているとか?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# sample
|
8
|
+
|
9
|
+
```SQL
|
10
|
+
|
11
|
+
create table tbl(id int not null unique,val int);
|
12
|
+
|
13
|
+
insert into tbl values(5,1),(7,2),(3,3),(1,4),(8,5);
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```SQL
|
20
|
+
|
21
|
+
select (select count(*)+1 from tbl as t2 where t2.id<t1.id) as rank,id,val
|
22
|
+
|
23
|
+
from tbl as t1 order by rank;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|