我将如何使用类似的 IN 表?这样我就可以在其中使用 % 了吗?我的意思是:

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 列”

最佳答案

您可以使用许多 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).*";

关于sql - MySQL IN 和 LIKE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3732246/

10-13 07:01