Php 在中使用查询通配符

Php 在中使用查询通配符,php,mysqli,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 我在充电日期附近有一个语法错误,我知道这个错误,我猜我不能像“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

我在充电日期附近有一个语法错误,我知道这个错误,我猜我不能像“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
更新:

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

(2017年、2018年)年(…)是一种选择吗?比较整数值时,不需要启动正则表达式引擎。@Progman,确定这是一个选项。作为替代解决方案添加。