数据库里面有个strat_time和end_time怎样判断当前时间是否在这个时间内datetime - 爱问答

(爱问答)

数据库里面有个strat_time和end_time怎样判断当前时间是否在这个时间内datetime

#创建存储过程
drop procedure if exists test;
create procedure test()
BEGIN
create table tmp1(startdate datetime,enddate datetime);
insert into tmp1 select startdate,enddate from d where startdate<=curdate() and enddate>=curdate();
update d set state=1 where startdate in(select startdate from tmp1) and enddate in(select enddate from tmp1);
update d set state=2 where startdate not in(select startdate from tmp1) and enddate not in(select enddate from tmp1);
drop table tmp1;
end;
#调用存储过程
call test();
思路:
创建一张表,先将当前时间与表内时间对比,如果当前时间在哪一行数据的开始时间范围和结束时间范围内则将数据插入tmp1表,进行update,将开始时间和结束时间都等于tmp1表内的startdate和enddate时改变该行state=1,不等于则改变该行state=2,删除使用过的tmp1表,结束。
注意:由于没有一个主键值,这里采用where startdate not in(select startdate from tmp1) and enddate not in(select enddate from tmp1)以及 where startdate in(select startdate from tmp1) and enddate in(select enddate from tmp1)并不是很好的选择。

相关标签:数据库

下一篇:这个怎么添加页数

上一篇:▲在5800计算器里怎么输入

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?