select (@xh := @xh + 1) as xh, a.* from (select * from auto where level = 3) a, (select @xh := 0) x
结果如下
mysql>select
*
from
a
+-----+
|
col
|
+-----+
|
0
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
+-----+
8
rows
in
set
(0.00
sec)
mysql>
set
@i
:=
0
select
@i
:=
@i
+
1
as
`order`,
a.*
from
a
order
by
col
desc
+-------+-----+
|
order
|
col
|
+-------+-----+
|
1
|
7
|
|
2
|
6
|
|
3
|
5
|
|
4
|
4
|
|
5
|
3
|
|
6
|
2
|
|
7
|
1
|
|
8
|
0
|
+-------+-----+
8
rows
in
set
(0.00
sec)
mysql>
序列只有db2oracle有,mysql没有序列的,不过你可以给你所所创建的表的主键设置为自增。
例如
create
table
A
(
id
int(20)
auto_increment
)
不过设置为自增的键必须是数值类型的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)