sql - mysql update a field plus 1 -


hi there want update field plus one.

for example:

if 0 -> 0+1 if 1 -> 1+1 

if code:

update article set likehits = '+1' id ='129' 

for result, result 1.

what's wrong?

likehits = '+1' not adds 1 field instead assign literal +1 likehits column value.

in order add 1 try this

update article  set likehits = likehits + 1 id ='129' 

however, looks likehits column of type nvarchar, if try (assuming likehits column stores numbers)

update article  set likehits = cast((cast(likehits int) + 1) nvarchar(64))  id ='129' 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -