问题
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 letters. So now i want to search records between two mgrs, so how can i do that? can i convert mgrs value to integer first and then use in between clause?
回答1:
Instead of BETWEEN
clause use STRCMP(expr1, expr2) function for string comparison operations:
WHERE STRCMP(mgrs, '42SWC227821555') >= 0 AND STRCMP(mgrs, '42SWC227821570') <= 0
回答2:
I will list some steps, instead of complete answer.
- Remove all alphabets from you value, means you can have 1 more customized column using function listed on this link
- Apply your filter on this column.
回答3:
You can use string expressions with BETWEEN comparison.
SELECT '42SWC2278215551' BETWEEN '42SWC227821555' AND '42SWd227821555'
-> 1
来源:https://stackoverflow.com/questions/25842771/how-to-use-alphanumeric-fields-with-between-clause-in-mysql