-3

I have some complicated task. I have some data in email column:

[email protected]

[email protected]

[email protected]

I need to get biggest number. In example its 5.

P.S. some time names can ends with number:

[email protected]

[email protected]

[email protected]

Here the real name is kuhari24. And biggest number is 3. Here is my answer, but it very ugly. Have some one better idea?

SELECT REPLACE(
    (
        SELECT REPLACE(
            (
                SELECT MAX(email) 
                FROM account 
                WHERE email LIKE 'borispil%'
            )
        , '[email protected]', '')
     )
, 'borispil', '') AS maxNumber
Anton Kolosok
  • 482
  • 9
  • 24

1 Answers1

-1

You can easy use REPLACE and +0 to find the Integer after a Name

SELECT field-realname, MAX(REPLACE(fiel-with-email,field-realname,'') + 0) as maximum_val FROM your_table group by fiels-realname;

Sample

MariaDB [(none)]> select REPLACE('[email protected]','kuhari24','') + 0;
+------------------------------------------------------+
| REPLACE('[email protected]','kuhari24','') + 0 |
+------------------------------------------------------+
|                                                    3 |
+------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

MariaDB [(none)]>
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39