Officer Bacon
Officer Bacon

Reputation: 734

How to check value contains character AND a number > x

I've got values stored in a table that are looking like this:

lk_release
A1
A2
C1
C2
C3
D1
D2
D3

I want to check if a value contains a certain character, like "C", AND if the number next to it is greater than 2.

My current Select-Statement looks like this:

SELECT distinct LK_Release FROM customer_requirement
WHERE LK_Release LIKE "%C%"
AND ... ;

Now i want to check if the number next to the values with "C" are bigger than 2. Is there simple way to do this? I was thinking of using some sub-queries, but i can't figure out a solution. Modifying the stored data is not an option.

Upvotes: 1

Views: 78

Answers (2)

Sashi Kant
Sashi Kant

Reputation: 13465

Try this::

SELECT * 
FROM customer_requirement
WHERE lk_release like "%C%" and SUBSTR(LK_Release,2,1) >2

Upvotes: 0

pala_
pala_

Reputation: 9010

select * 
  from customer_requirement 
  where lk_release like "%C%" 
    and right(lk_release, 1) > 2

here's a demo: http://sqlfiddle.com/#!9/4ca77/1

Note it relies on it always being a single digit, and always being at the end of the string.

Upvotes: 2

Related Questions