mysql, 一个表里有 10条记录,有一个rowNum列,记录的是行号,
0
1
9
如果把第3,5,7条记录删掉, 我希望删完之后能这样
0
1
2
3
4
5
6而不是
0
1
3
5
7
8
9请问咋整。
0
1
9
如果把第3,5,7条记录删掉, 我希望删完之后能这样
0
1
2
3
4
5
6而不是
0
1
3
5
7
8
9请问咋整。
解决方案 »
- mysql api mysql_fetch_row 会因为系统压力而执行出错吗?
- MySQL中存储过程stored procedure中报错,END这里画浪线啊
- 各位大侠MYSQL数据库免费版本目前哪个版本最稳定?
- mysql 查询问题
- 两个连接,插入数据后的查询问题
- 要实现这样的效果用什么样的语句?
- 如何知道insert语句已经成功插入记录
- 问一个问题:为什么MySQL发展的这么慢?
- 请问,MYSQL中 char(varchar) 字段大小是字节还是字?也就是说汉字和英文字母能存储的最大字数相同么?
- max does not exist
- 问一个很蠢的问题,mysqlimport怎么用
- 存储过程中的游标
MySQL中的ROWNUM的实现
1、 可以用JOIN实现2、用变量累加得到行号
+----+
| id |
+----+
| 0 |
| 1 |
| 2 |
| 4 |
| 6 |
| 8 |
| 9 |
+----+
7 rows in set (0.00 sec)mysql> update tx t1,
-> (select id,(select count(*) from tx where id<t.id) as newid from tx t) t2
-> set t1.id=t2.newid
-> where t1.id=t2.id;
Query OK, 4 rows affected (0.06 sec)
Rows matched: 7 Changed: 4 Warnings: 0mysql> select * from tx;
+----+
| id |
+----+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+----+
7 rows in set (0.00 sec)mysql>
select id,@ee:=@ee+1 from ttqorselect a.id,count(b.id) from ttq a
left join ttq b on a.id>b.id
group by a.id
(select a.id,count(b.id) as id1 from ttq a
left join ttq b on a.id>b.id
group by a.id) b1
set a1.id=b1.id1
where a1.id=b1.id