小编典典

MySQL IN与LIKE

sql

我如何将IN表与like一起使用?这样我就可以在其中使用%了?我的意思是:

SELECT fields 
  FROM table 
 WHERE age = "50" 
   AND name IN ("tim", "bob", "nancy", "john");

我已经尝试过:

SELECT fields 
  FROM table 
 WHERE age = "50" 
   AND name LIKE ("2010-09-17%", "2010-09-16%")

但是它给出了错误“操作数应包含1列”


阅读 176

收藏
2021-05-05

共1个答案

小编典典

您可以使用许多LIKE表达式:

SELECT fields 
  FROM table 
  WHERE age = "50" 
        AND (
             name LIKE "2010-09-17%" 
             OR name LIKE "2010-09-16%"
            );

或者您可以使用正则表达式:

SELECT fields 
  FROM table 
 WHERE age = "50" 
       AND name REGEXP "2010-09-17.*|2010-09-16.*";

或者,巧妙地

SELECT fields 
  FROM table 
 WHERE age = "50" 
       AND name REGEXP "2010-09-1(6|7).*";
2021-05-05