简体   繁体   English

Select * From Table Where Name in like(通配符)

[英]Select * From Table Where Name in like (wildcards)

Is it possible to combine SQL statements such as是否可以组合 SQL 语句,例如

SELECT * FROM X WHERE Y LIKE '%a%' OR Y LIKE '%b%' OR Y LIKE '%c%' OR Y LIKE '%d%'

with something like

SELECT * FROM X WHERE Y IN ('a', 'b', 'c', 'd')

so I don't have to write one big statement such as it is now:所以我不必像现在这样写一个大声明:

IF NOT EXISTS(SELECT * FROM X WHERE Y LIKE '%a%' OR Y LIKE '%b%' OR Y LIKE '%c%' OR Y LIKE '%d%')
    BEGIN
        /* code */
    END

Would be very nice to use something like SELECT * FROM X WHERE Y IN LIKE ('%a%', '%b%', etc..) Appreciate all help and suggestions, thanks.使用像SELECT * FROM X WHERE Y IN LIKE ('%a%', '%b%', etc..)这样的东西会非常好SELECT * FROM X WHERE Y IN LIKE ('%a%', '%b%', etc..)感谢所有帮助和建议,谢谢。

请使用以下代码解决您的问题,如果仍有问题,请尝试让我知道。

SELECT * FROM X WHERE Y LIKE '%[a-d]%'

If your database supports RegEx, you can use that.如果您的数据库支持 RegEx,则可以使用它。 For example:例如:

SELECT * FROM X WHERE Y SIMILAR TO '%(a|b|c|d)%' in PostgreSQL, and SELECT * FROM X WHERE Y SIMILAR TO '%(a|b|c|d)%'在 PostgreSQL 中,和

SELECT * FROM X WHERE Y REGEXP 'a|b|c|d' in MySQL. SELECT * FROM X WHERE Y REGEXP 'a|b|c|d'在 MySQL 中。

LIKE '%[ad]%' won't work because LIKE s in most databases don't accept regex patterns. LIKE '%[ad]%'将无法工作,因为LIKE S IN大多数数据库不接受正则表达式模式。 This will just expect the literal text [ad] somewhere in the string.这将只期望字符串中某处的文字文本[ad] How each database interprets regular expression (or native pattern) varies a lot.每个数据库如何解释正则表达式(或本机模式)有很大差异。 So you need to tailor these things to your database.所以你需要根据你的数据库定制这些东西。 For example, the following will not work in PostgreSQL:例如,以下内容在 PostgreSQL 中不起作用

SELECT * FROM X WHERE Y SIMILAR TO 'a|b|c|d'

because PostgreSQL will expect the whole string to be 'a', 'b', 'c', or 'd'.因为 PostgreSQL 会期望整个字符串为 'a'、'b'、'c' 或 'd'。

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

相关问题 从名称为%O%的表中选择* - select * from table where name like %O% 从表 B 中删除,其中列值类似于带有通配符的表 a - Delete from table B where column value like table a with wildcards select * from table_name where column like'' - select * from table_name where column like '&nbsp' SELECT * FROM table WHERE * LIKE (SELECT * FROM table WHERE * = *) - SELECT * FROM table WHERE * LIKE (SELECT * FROM table WHERE * = *) SQL:从@variable 中选择表的表值,例如'Select * from @Table_name' where @table_name=[DB_Name].[Schema_name].[table_name] - SQL : selecting the table values of table from @variable like 'Select * from @Table_name' where @table_name=[DB_Name].[Schema_name].[table_name] SQL从表中选择Like Column Name - SQL Select Like Column Name from table SELECT FROM表,其中表名位于变量SQL中 - SELECT FROM Table where the table name is in a variable SQL 如何从表名称为局部变量的表中选择(informix) - How to select from table where the table name is a local variable(informix) Select object 的名称在另一个表中的表中的最高平均值 - Select top average from a table where the name of the object is in another table Postgres jsonb列从数组中选择字符串匹配通配符 - Postgres jsonb column select from array where a string matches wildcards
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM