如何在MySQL中增加计数器并返回值

| 我有一个包含键列和计数器列的表。我需要做这样的事情:
SELECT counter=counter+1 FROM table WHERE key=\'mykey\'
基本上,我需要增加Counter列并返回新值。如何在MySQL 5.5中做到这一点?     
已邀请:
        
update mytable set count=last_insert_id(counter+1) where key=\'mykey\'
然后
select last_insert_id()
last_insert_id()
可以将参数传递给\'set \'它(并返回该值),并且不带参数调用它会再次返回该值。
last_insert_id()
使用的内部状态是每个连接,这意味着在另一个连接上发出的相同
update
语句不会影响第一个连接。 参考:
last_insert_id()
    

要回复问题请先登录注册