我有一个表aa,里边有三个字段id,shop_id,sort_id
表里边有些数据
1,1,0
2,1,0
3,2,0
4,2,0
我现在怎么能把sort_id更新为这样的呢?
1,1,1
2,1,2
3,2,1
4,2,2
表里边有些数据
1,1,0
2,1,0
3,2,0
4,2,0
我现在怎么能把sort_id更新为这样的呢?
1,1,1
2,1,2
3,2,1
4,2,2
解决方案 »
- pgsql 存储过程返回集合的问题
- 问大家一个弱弱的问题...
- 给java应用程序分配的'csfdp'@'192.56.231.12'报错,不识别!
- ERROR 1336 (0A000): Dynamic SQL is not allowed in stored function or trigger
- 不用ODBC如何连接到Mysql?
- 请问这个错误是什么意思。。。Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\w
- 有关论坛和用户管理的库表?
- mysql修改列属性
- 帮我看下这个SQL语句的错误在哪里?
- mysql 在查询的结果中增加一行标记序号的伪列
- 运行mysql开发包,程序就挂掉
- 如何修改一个字段的部分数据
id,
shop_id,
(select count(1) from aa where shop_id=t.shop_id and id<t.id)+1 as sort_id
from aa t
我来写更新吧。
^^
update aa as a,
(
select tt.id,(select count(*)+1 from aa where shop_id = tt.shop_id and id< tt.id) as c
from aa as tt
) as b
set a.short_id = b.c where a.id = b.id;
不知道可以嗎?
不知道可以嗎?