2

在 MySQL 上是否有任何快捷方式?

WHERE month = 'January' OR month = 'January' OR month = 'February' OR month = 'March' OR month = 'April' OR month = 'May' OR month = 'June' 

这个我试过了,好像不行

WHERE month = '(January || February || March || April || May || June)'

有什么帮助吗?

4

4 回答 4

4

要回答您的问题:

WHERE `month` IN ('January', 'February', 'March', 'April', 'May', 'June');

在php中

$months = array('January', 'February', 'March', 'April', 'May', 'June');
$sql .= "WHERE `month` IN ('".implode("', '", $months)."')";

除此之外:当存储日期(例如月份)时,最好将它们存储为整数值,而不是字符串。这将有助于提高性能,I18N,如果你使用 int 值,你可以使用 BETWEEN

WHERE `month` BETWEEN 1 AND 6
于 2012-09-03T05:55:17.660 回答
3

是的,您可以IN为此使用子句。像这样:

WHERE month in ('January','February','March','April','May','June')
于 2012-09-03T05:47:36.220 回答
2

使用IN子句。

WHERE `month` IN ('January','February','March','April', 'May','June')

看到反引号了month吗?由于存在名为Month( )的内置函数,它转义了关键字

于 2012-09-03T05:47:34.707 回答
2

尝试..

WHERE month IN ('January', 'February', 'March', 'April', 'May', 'June');
于 2012-09-03T05:48:23.613 回答