★更新排序第一的数据某一字段SQL问题!
★先看我的数据库表:(ACCESS的)
表 AAA 里面有字段 name , num
能不能用一句 SQL 完成这更新功能?
(我要更新排序后 num 最高的那条数据 num+1)
Set rs=conn.execute( "SELECT top 1 name FROM [AAA] WHERE name= ' "&name& " ' order by num desc ")
upname=rs(0)
conn.execute( "update [AAA] set num=num+1 where name= ' "&upname& " ' ")
我想用一句SQL完成。
conn.execute( "update [AAA] set num=num+1 where (SELECT top 1 name FROM [AAA] WHERE name= ' "&name& " ' order by num desc) ")
★能行吗?
------解决方案--------------------那你要另外加个条件了。。。。。还有什么字段是唯一的直接加上就行了
第二次排序时选个唯一值
如:
conn.execute( "update [AAA] set num=num+1 where name= '(SELECT top 1 name FROM [AAA] WHERE name= ' "&name& " ' order by num desc) ' order by id desc ")