select * from purchase_items where item_code between '180' and '186'
我有一个表purchase_items,例如,我有以下值。
item_code
180
182
183
1852563
186cf2564
186cf2564
187sa5635
如果我在180
和187
之间选择,则显示所有值。
但我需要180
到183
之间的范围它应该显示以下内容:
180
182
183
如果我将范围186cf2564
给187sa5635
它应该显示:
186cf2564
186cf2564
187sa5635
只有如何让它显示正确的输出?
从示例数据中,您可以选择字符串的数字部分。它更多的是硬编码工作,如果您的数据一致,则此查询有效
select * from purchase_items where left( item_code,3) between '180' and '186'
用于选择行ICNF1 to ICNF7
select * from purchase_items where Right( item_code,1) between 1 and 7
对于186cf2564到187sa5635
select * from purchase_items where left( item_code,3) between '186' and '187'
试试这个 -
select * from purchase_items where item_code between '180' and '183'
select * from purchase_items where LEFT(item_code,3) between '186' and '187'