解法收录1题6解,参考@啥也不会的老蒟蒻 ,第一个题解

字符串匹配(近似查找法)

用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
全部评论

相关推荐

想润的芹菜人狠话不多:把其中一个老总放中间都会得罪另一个
点赞 评论 收藏
分享
牛客737698141号:他们可以看到在线简历的。。。估计不合适直接就拒了
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务