简体   繁体   English

如果列是文本和数字,我如何从列值大于某个值的mysql表中选择

[英]how can i select from a mysql table where column value is greater than some value if the column is text and numbers

I have a table called "products" where one column is "SerialNumber". 我有一个名为“产品”的表,其中一列为“ SerialNumber”。 The problem is that this column is text latin1_swedish_ci and values are like "BC00001, BC0002, etc. i need to select all products where serial number is for example greater than some given serial number. i tried selecting like this: 问题在于该列为文本latin1_swedish_ci,其值类似于“ BC00001,BC0002等。我需要选择序列号大于某个给定序列号的所有产品。我尝试选择以下方式:

SELECT * FROM 'products' WHERE 'SerialNumber' >= 'BC00563' 

But since this column is text, it' not working. 但是由于此列是文本,因此无法正常工作。 I can't modify the table structure because the this table laready has 20.000 + records. 我无法修改表结构,因为此表已经有20.000条记录。 Any help appreciated! 任何帮助表示赞赏!

Assuming the value is always two characters followed by numbers, you can strip out the characters and convert the remaining values into number for the comparison, eg: 假设值始终是两个字符后跟数字,则可以去除字符并将剩余的值转换为number以进行比较,例如:

SELECT * 
FROM `products` 
WHERE `SerialNumber` >= 
    CASE WHEN 'BC00563' regexp '[A-Z]' THEN 
    CONVERT(SUBSTRING("BC00563", 3, LENGTH("BC00563")), UNSIGNED) 
    ELSE 'BC00563' END;

You can use the column name instead of constant value. 您可以使用列名代替常量值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅当字段中的值等于或大于输入值时,才如何从MySQL表的值中减去用户输入值? - How can I subtract a user input value from a value in a MySQL table only if the value in the field is equal to or greater than the input value? 使用PHP / MySQL,如何从具有多值列内容的表中进行选择 - Using PHP/MySQL, how can I SELECT from table with multi-value column content 如何从mysql表中选择包含至少一个大于搜索值的所有行? - How To Select all row from mysql table that contains atleast one value greater than search value? mysql select * from table from table where column a value = column b value laravel - mysql select * from table where column a value = column b value laravel 从表中选择*,其中column =值^ column2 =值 - select * from table where column = value ^ column2= value 如何正确使用Mysql选择* FROM表WHERE column ='Any_value_in_Array' - how to properly use Mysql to SELECT * FROM table WHERE column='Any_value_in_Array' 如何显示大于或等于mysql表列月份的数据? - How can I show data which is greater than or equal to mysql table column month? 如何通过列/字段值选择MySQL表中的行? - How do I select rows in a MySQL table by column/field value? MySQL选择带有替换文本的列,该列等于一个值 - MySQL select a column with replaced text where it equals a value 如何在mysql数据库的特定列中选择最后一个值? - How can i select the last value in a particular column in mysql database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM