Norse
Norse

Reputation: 5757

MYSQL How to find numbers near a string

I have one of these variations in a field:

Amount Used: 4/11
Amount Used : 4 / 11
4 / 11  Amount Used

Each row in my table contains one of these variations with a different set of numbers.

Is it be possible to find the numbers near the string Amount Used, regardless of whatever tiny variations there may be in the syntax near it?

I've atleast started with:

SELECT * FROM mytable WHERE
`file` LIKE '%Amount Used%'

but am not sure where to go from here

Upvotes: 1

Views: 53

Answers (1)

Joe G Joseph
Joe G Joseph

Reputation: 24046

try this:

When you replace the constants (ie,Amount Used , : ) , you will get the variable numbers

SELECT trim(replace(replace(`file`,'Amount Used',''),':','')) as `values`
FROM mytable 
WHERE `file` LIKE '%Amount Used%'


SQL Fiddle demo

Upvotes: 4

Related Questions