XML中MySQL语句和WHERE结合使用

该段内容是一个SQL查询,用于从tb_stamp表中选择数据并LEFTJOINview_seal_count和view_dept视图,根据多个条件进行过滤,如stamp_name,stamp_type,stamp_org等。查询还考虑了有效日期范围,并在where子句中处理了空值情况。
摘要由CSDN通过智能技术生成
<select id="selectTbStampList" parameterType="TbSeal" resultMap="TbStampResult">
    select sta.stamp_id, sta.stamp_name, sta.stamp_code,sta.picture_data,sta.picture_type,sta.stamp_type,sta.status,
    sta.valid_start, sta.valid_end, sta.stamp_org,sc.num,vd.dept_name,sta.sealModel_name,sta.sealModel_org from tb_stamp sta
    LEFT JOIN view_seal_count sc
    ON sta.stamp_id=sc.seal_id
    LEFT JOIN view_dept vd
    ON vd.dept_id=sta.organ_id
    <where>
        <if test="stampName != null  and stampName != ''">and sta.stamp_name like concat('%', #{stampName}, '%')
        </if>
        <if test="stampType != null  and stampType != ''">and sta.stamp_type = #{stampType}</if>
        <if test="stampOrg != null  and stampOrg != ''">and sta.stamp_org = #{stampOrg}</if>
        <if test="pictureData != null  and pictureData != ''">and sta.picture_data = #{pictureData}</if>
        <if test="pictureType != null  and pictureType != ''">and sta.picture_type = #{pictureType}</if>
        <if test="status != null  and status != ''">and sta.status = #{status}</if>
        <if test="organId != null  and organId != ''">and vd.dept_real_id = #{organId}</if>
        <if test="stampCode != null  and stampCode != ''">and sta.stamp_code = #{stampCode}</if>
        <if test="makeOrgCode != null  and makeOrgCode != ''">and sta.make_org_code = #{makeOrgCode}</if>
        <if test="params != null ">
            <if test="params.beginValidStart != null and params.beginValidStart != ''">
                <![CDATA[
                    and sta.valid_start >= CONCAT(#{params.beginValidStart},' 00:00:00')
                ]]>
            </if>
            <if test="params.endValidEnd != null and params.endValidEnd != ''">
                <![CDATA[
                  and sta.valid_end <= CONCAT(#{params.endValidEnd},' 23:59:59')
                ]]>
            </if>
        </if>
        AND status=1
    </where>
    ORDER BY sta.create_time DESC
</select>

where中判断不同表的字段条件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值