sql - Postgres : Select the maximum integer substring of a column value -


i'm using postgresql , i'm having trouble formulating right sql query. title of question might sound weird, i'm trying achieve. i'm performing data curation particular table. if have table product containing :

id | designation --------------------- 1  | ir15a1021 2  | ir15a1001 3  | ir15a1050 4  | ab100  5  | ar100 

what want to:

1) integer substring of only , exactly records designation whose pattern starts 'ir15a'. , integer substring, meaning number after starting string 'ir15a'. (1021,1001,1050)

2) maximum integer substring in case :

maximum integer substring : 1050  

because other ir15a have max substrings less (1021 , 1001).

assume correct conditions.

1) substring after ir15a integer no worrying type, integer. 2) ignore other designation patterns. ir15a.

i've managed '%ir15a%' wildcard search haven't found solution cut integer substring out of , compare others maximum. thanks!

try this:

select max(cast(substring(designation '....$') int)) tab designation 'ir15a%' 
  1. take rows ir15a using like 'ir15a%'
  2. remove ir15a using substring(designation '....$').
  3. convert int using cast
  4. take max value using max()

sql fiddle demo


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -