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>
比如说你创建了一个表userinfoscreate table userinfos(
userid int primary key,
username varchar(20)
)
//给userinfos添加序列
update userinfos set userid = last_insert_id(userid+1)
//然后查询序列
select last_insert_id()
或者也可以这样
create table userinfos(
userid int primary key not null auto_increment,
username varchar(20)
)
select a.*,(select count(*) from tbl where col<=a.col) as rownum
from tbl a
mysql 没有oracle里面的rownum函数,用这个sql可以模拟下,但是如果数据量大的话,可能执行很慢。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)