如何执行 SQL 查询从包含多个日期值的同一字段中检索特定日期范围内的数据?

问题描述 投票:0回答:1

字段 realStartTime 可能包含格式类似于“2022-09-14 11:38:21,2022-09-14 18:00:00”的值,多个时间戳用逗号分隔。

我想实现一个查询,如果realStartTime中以逗号分隔的任何时间作为输入传递时落在指定的时间范围内,则应该检索它。如果有多个匹配的时间戳,则只应返回一条记录。

目前,该实现仅支持 MyBatis 中 realStartTime 包含单个时间戳值的查询。

<select id="getEventPlanByCodeDateLimitSimple" resultMap="EventPlanRecordAllMap">
select
    epr.*
from
    event_plan_record epr
where
    epr.realStartTime BETWEEN #{startDate} AND #{endDate} order by epr.realStartTime desc limit #{page},#{count};
</select>
java sql mysql database dolphindb
1个回答
0
投票

这是一对多关系,您应该将这些日期存储在单独的表中,例如 epr_RealStartTime。

表 event_plan_record 需要引用 epr_RealStartTime,以便您可以管理此类关系。

© www.soinside.com 2019 - 2024. All rights reserved.