mybatis.xml根据时间查询最接近该时间数据遇到查询数据为空问题

    <select id="selectLatelyData" resultType="com.hrsoft.model.WaterLevelEntity" >
        SELECT *,ABS(TIMESTAMPDIFF(SECOND,<![CDATA[ CONCAT(#{paramDate},'00:00:00' )]]>,datetime)) as diff
        FROM water_level
        WHERE 1=1
            <![CDATA[  and datetime <= CONCAT(#{addDate},'00:00:00' )]]>
            <![CDATA[  and datetime >= CONCAT(#{minusDate},'00:00:00' )]]>
    </select>
</mapper>
使用下面函数转换

<![CDATA[ and datetime <= CONCAT(#{addDate},'00:00:00' )]]>

  sql.append(" and a.registerTime >= convert(datetime,?) and a.registerTime <= convert(datetime,?) ");

 

查询不到数据是 因为我我的传参是String类型而数据库是dateTime类型所有要用到上面函数进行转换

 不同类型转char

  SELECT CAST(dt_beta1 AS CHAR) beta1,
               CAST(dt_beta2 AS CHAR) beta2,
               CAST(dt_h11 AS CHAR)   h11,
               CAST(dt_h12 AS CHAR)   h12,
               CAST(dt_h21 as CHAR)   h21,
               CAST(dt_h22 as CHAR)   h22,
               CAST(dt_s1 as CHAR)    hrs1,
               CAST(dt_s2 as CHAR)    hrs2,
               CAST(dt_miu11 as CHAR) miu11,
               CAST(dt_miu12 as CHAR) miu12,
               CAST(dt_miu21 as CHAR) miu21,
               CAST(dt_miu22 as CHAR) miu22
--                CAST(dt_s3 as CHAR)    hrs3,
--                CAST(dt_h31 as CHAR)   h31,
--                CAST(dt_h32 as CHAR)   h32,
--                CAST(dt_miu3 as CHAR) beta3
        FROM t_dt
        WHERE dt_name = 'd'
          AND dt_default = (CASE
                                WHEN (SELECT COUNT(*) FROM t_dt WHERE dt_name = 'd') > 1 THEN 0
                                ELSE
                                    1
            END
            )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值