A
A
Alexey2020-05-15 22:15:40
MySQL
Alexey, 2020-05-15 22:15:40

How to make a number from a string, and then again a string?

I have a table of accelerations: id (int), speed (varchar)
The data is filled in this way:
1 | 4x2
| 10x3
| 15x4
| 12x
I need to find the maximum value. If I compare varchar, then 4x is the maximum...
How can I make a SELECT that translates to numbers first, selects the maximum, and then translates to a string and appends 'x' at the end? I tried to cast in cast, but I get an error:
CAST((SELECT CAST(MAX(CAST(speed AS DECIMAL))) FROM PC, CHAR(4)) + 'x'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2020-05-15
@KingstonKMS

Remove x and store numbers. When selecting, add x when necessary using CONCAT functions

L
Lazy @BojackHorseman MySQL, 2020-05-15
Tag

very simple .

SELECT * FROM Test ORDER BY CAST(REPLACE(speed, 'x', '') AS UNSIGNED) DESC LIMIT 1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question