题解 115 | #删除记录(一)#

【场景】:按照条件(批量)删除多值 【分类】:删除记录、日期函数

分析思路

难点:

1.如何处理时间条件

方法一、日期减去日期得到分钟

timestampdiff函数

  • [使用]:timestampdiff(minute, begin, end) < 5

方法二、日期减去(加上)分钟得到日期

date_sub函数

  • [使用]:date_sub(end, interval 5 minute ) < begin

date_add函数

  • [使用]:date_add(begin, interval 5 minute ) > end

批量删除

  • [使用]:批量删除一般用id删除
delete from table where id in(str1,str2,...,strn)

扩展

前往查看:MySQL 删除数据 前往查看:MySQL 日期函数、时间函数在实际场景中的应用

求解代码

方法一:

timestampdiff

delete from exam_record
where timestampdiff(minute, start_time, submit_time) < 5 
and score < 60

方法二:

date_sub

delete from exam_record
where date_sub(submit_time, interval 5 minute ) < start_time 
and score < 60

方法三:

date_add

delete from exam_record
where date_add(start_time, interval 5 minute ) > submit_time 
and score < 60
全部评论

相关推荐

06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
评论
16
7
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务