MySQL Executing string as math operation -


in column have this:

amount:

12 2x25 192 

how possible multiply in example 2x25 order correctly asc.

my starting point:

select * table order replace(amount,'x','*') asc 

tia frgtv10

try this

  select    cast(if(amount '%x%', substring_index(amount, 'x', 1) *   substring_index(amount, 'x', -1) , amount)  unsigned ) amount    table1   order amount asc 

demo here

steps , explaining :

  • locate fields x value

  • sbstring left , right , multiply it.

  • then cast multiplication unsigned.

  • order asc


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -