How to use alphanumeric fields with BETWEEN clause in Mysql?

前端 未结 3 832
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 10:44

I have a table that contain a field names as mgrs, the value that stored in mgrs fields is like \'42SWC227821555\' may contain more charachters, and may contain lower case lette

相关标签:
3条回答
  • 2021-01-26 11:05

    Instead of BETWEEN clause use STRCMP(expr1, expr2) function for string comparison operations:

    WHERE STRCMP(mgrs, '42SWC227821555') >= 0 AND STRCMP(mgrs, '42SWC227821570') <= 0
    
    0 讨论(0)
  • 2021-01-26 11:06

    You can use string expressions with BETWEEN comparison.

    SELECT '42SWC2278215551' BETWEEN '42SWC227821555' AND '42SWd227821555'
    -> 1
    
    0 讨论(0)
  • 2021-01-26 11:07

    I will list some steps, instead of complete answer.

    1. Remove all alphabets from you value, means you can have 1 more customized column using function listed on this link
    2. Apply your filter on this column.
    0 讨论(0)
提交回复
热议问题