字符串匹配(近似查找法)
用like来查找
1
2
3
4
|
select order_num, order_date
from Orders
where order_date like '2020-01%'
order by order_date
|
切割字符串
1
2
3
4
|
select order_num, order_date
from Orders
where left(order_date, 7) = '2020-01'
order by order_date
|
字符串比较
1
2
3
4
|
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)
1
2
3
4
|
select order_num, order_date
from Orders
where order_date regexp '2020-01'
order by order_date
|
时间函数匹配
1
2
3
4
|
select order_num, order_date
from Orders
where year(order_date) = '2020'and month(order_date) = '1'
order by order_date
|
利用date_format函数 (参考其中的匹配规则进行匹配)
1
2
3
4
|
select order_num, order_date
from Orders
where date_format(order_date, '%Y-%m')='2020-01'
order by order_date
|