mysql判断当前时间是否在开始与结束时间之间且开始与结束时间允许为空
作者:纵有千千星晚 时间:2024-01-23 17:35:43
需求:查询进行中的活动数据
进行中一共有以下几种情况:
1.开始时间为空,结束时间为空, 此结果数据将永远为进行中的数据
2.开始时间为空,结束时间不为空,则当前时间在结束时间之前,为进行中的数据
3.开始时间不为空,结束时间为空,则当前时间在开始时间之后,为进行中的数据
4.开始时间不为空,结束时间不为空,则当前时间在开始与结束时间段之内的数据为进行中数据
下面sql则查询的是满足以上四种需求的结果集,达标题需求
SELECT * FROM
表名
WHERE 1=1
and(start_time is null or start_time<now())
and(end_time is null or end_time>now())
mybatis写法,开始时间与结束时间传入参数允许为空
如图所示:
<if test="record.startDate != null and record.startDate != '' or record.endDate != null and record.endDate != '' ">
AND id in
(select id from rht_product_price where 1=1
<if test="record.startDate != null and record.startDate != ''">
and start_date <= #{record.startDate,jdbcType=VARCHAR}
</if>
<if test="record.endDate!= null and record.endDate != ''">
and end_date >= #{record.endDate,jdbcType=VARCHAR}
</if>
)
</if>
来源:https://blog.csdn.net/weixin_44980116/article/details/112677751
标签:mysql,当前时间,开始与结束时间之间
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
css实现简单圆角效果
2008-11-27 13:11:00
![](https://img.aspxhome.com/file/UploadPic/200811/27/e59c86e8a792-560x156-82s.jpg)
mysql常用命令行操作语句
2024-01-12 23:51:20
python 的赋值语句和基本输入输出详解
2021-07-29 13:55:55
![](https://img.aspxhome.com/file/2023/3/114563_0s.png)
MySql批量插入优化Sql执行效率实例详解
2024-01-18 07:52:06
Python Pandas聚合函数的应用示例
2022-12-13 22:39:31
快速了解Python相对导入
2023-07-29 18:35:30
python教程之进程和线程
2021-09-27 02:54:00
![](https://img.aspxhome.com/file/2023/5/83725_0s.png)
Python操作列表的常用方法分享
2021-06-02 12:41:29
PHP 简单日历实现代码
2023-07-01 12:00:01
![](https://img.aspxhome.com/file/2023/1/55341_0s.jpg)
PHP Session条件竞争超详细讲解
2023-06-03 12:49:00
![](https://img.aspxhome.com/file/2023/7/55337_0s.png)
浅谈Python3实现两个矩形的交并比(IoU)
2021-09-06 19:31:56
![](https://img.aspxhome.com/file/2023/7/67247_0s.jpg)
MySQL延时复制库方法详解
2024-01-26 14:21:51
python 查看cpu的核数实现
2023-01-02 21:09:31
![](https://img.aspxhome.com/file/2023/3/80493_0s.png)
Python time模块时间获取和转换方法
2022-06-07 11:14:30
window.print()局部打印三种方式(小结)
2024-04-28 10:18:57
Python pandas的八个生命周期总结
2023-02-08 17:01:04
关于Python字典(Dictionary)操作详解
2022-02-04 15:25:01
MySQL数据库优化之分表分库操作实例详解
2024-01-20 10:33:53
php之redis短线重连案例讲解
2023-06-12 13:16:04
Python技能树共建之python urllib 模块
2023-02-07 04:02:40