与In查询通配符



我有此查询:

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附近有一个语法错误,我知道我猜我不能使用" In"的错误,无论如何我是否可以执行与实际工作的逻辑?

我想,您只需要从日期起就需要一年,而您想搜索多年。

那么您的解决方案应该看起来像以下内容:

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

最新更新