使用IN查询通配符

时间:2017-09-23 13:46:43

标签: php mysqli

我有这个问题:

select * from orders where week_of_year = '40' and user_id = '8631' and charge_date like in ('2017%','2018%') order by id desc limit 1

我在charge_date附近有语法错误,我知道错误我猜测我不能像在'中那样使用,无论如何我可以做同样的逻辑实际上工作?

1 个答案:

答案 0 :(得分:1)

我想,您只需要从该日期起一年,并且您想要搜索多个可能的年份。

然后您的解决方案应如下所示:

select * from orders where week_of_year = '40' and user_id = '8631' and YEAR(charge_date) REGEXP '2017|2018' order by id desc limit 1

<强>更新 使用IN

的替代解决方案
select * from orders where week_of_year = '40' and user_id = '8631' and YEAR(charge_date) IN (2017, 2018) order by id desc limit 1