MYSQL - how to string comparisons and query? -


+--------------------+---------------+------+-----+---------+-------+ | id                 | gkey          |goods | pri | country | | +--------------------+---------------+------+-----+---------+-------+ | 1                  | book-1        | 1    | 10  |         |       | | 2                  | phone-1       | 2    | 12  |         |       | | 3                  | book-2        | 1    | 13  |         |       | | 4                  | book-3        | 1    | 10  |         |       | | 5                  | phone-2       | 2    | 10  |         |       | | 6                  | phone-3       | 2    | 20  |         |       | | 7                  | book-10       | 2    | 20  |         |       | | 8                  | book-11       | 2    | 20  |         |       | | 9                  | book-20       | 2    | 20  |         |       | | 10                 | book-21       | 2    | 20  |         |       | | 11                 | phone-30      | 2    | 20  |         |       | +--------------------+---------------+------+-----+---------+-------+  

above table. want records gkey > book-2, can tell me expression mysql?

using " gkey>'book-2' " cannot correct results.

how (something like):

(this mssql - guess similar in mysql)

select     *    (       select           *,          index = convert(int,replace(gkey,'book-',''))       table                 gkey 'book%'    ) sub    sub.index > 2 

by way of explanation: inner query recreates table, book rows, , column containing index in right data type make greater comparison work numerically.

alternatively this:

select    * table    (      case         when gkey 'book%'            case when convert(int,replace(gkey,'book-','')) > 2 1            else 0            end         else 0         end    ) = 1 

essentially problem need check book before turn index numberic, other values of gkey create error (without doing clunky string handling).


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -