收集一下这题的各种解法
字符串匹配(近似查找法)
用like来查找
select order_num, order_date
from Orders
where order_date like '2020-01%'
order by order_date
切割字符串
select order_num, order_date
from Orders
where left(order_date, 7) = '2020-01'
order by order_date
字符串比较
select *
from Orders
where order_date >= '2020-01-01 00:00:00' and order_date <= '2020-01-31 23:59:59'
order by order_date;
用正则来查找(效率不如like,能用like就用like)
select order_num, order_date
from Orders
where order_date regexp '2020-01'
order by order_date
时间函数匹配
select order_num, order_date
from Orders
where year(order_date) = '2020' and month(order_date) = '1'
order by order_date
利用date_format函数 (参考其中的匹配规则进行匹配)
select order_num, order_date
from Orders
where date_format(order_date, '%Y-%m')='2020-01'
order by order_date