话不多说直接上代码
gldjs 是List
<foreach collection="gldjs" item="gldj" open="(" close=")" index="index" separator="or">
gldj = ${gldj}
and exists(select 1
from tb_fw_zfjc b
where yxzt = '1'
and a.syfw_id = b.syfw_id
<choose>
<when test="gldj == 1 ">
and timestampdiff(day, jcrq, curdate()) > (30 - 3))
</when>
<when test="gldj == 2 ">
and timestampdiff(day, jcrq, curdate()) > (90 - 7))
</when>
<when test="gldj == 3 ">
and timestampdiff(day, jcrq, curdate()) > (365 - 15))
</when>
</choose>
</foreach>
拼接的结果
and
( gldj = 1
and exists(select 1
from tb_fw_zfjc b
where yxzt = '1'
and a.syfw_id = b.syfw_id and timestampdiff(day, jcrq, curdate()) > (30 - 3))
)
or
( gldj = 3
and exists(select 1
from tb_fw_zfjc b
where yxzt = '1'
and a.syfw_id = b.syfw_id and timestampdiff(day, jcrq, curdate()) > (365 - 15))
)
or
( gldj = 2
and exists(select 1
from tb_fw_zfjc b
where yxzt = '1'
and a.syfw_id = b.syfw_id and timestampdiff(day, jcrq, curdate()) > (90 - 7))
)
评论区