I am new to MySQL and i am storing a version number in a column called version which is a string.I want to convert it into integer and increment by one. For example if version = 2.2.1....By running a query i want to change it to 2.2.2 is there anyone who did similar queries?
1 Answer
You could use some string function
SELECT CONCAT(
LEFT(your_column, LENGTH(your_column) - LOCATE('.', REVERSE(your_column))+1),
CAST(SUBSTRING_INDEX(your_column, '.', -1) AS UNSIGNED) +1
)
eg
SELECT CONCAT(
LEFT("2.2.2", LENGTH("2.2.2") - LOCATE('.', REVERSE("2.2.2"))+1),
CAST(SUBSTRING_INDEX("2.2.2", '.', -1) AS UNSIGNED) +1
)
1 Comment
Greeshma
this query is giving result as 2.2..1