2 qq 34806078 qq_34806078 于 2016.05.12 01:30 提问

各位大神麻烦帮忙看下SQL对不对

parameterType="String">
SELECT
receive_car_code,
use_time,
sc.coupon_name
FROM
car_coupon cc
LEFT JOIN (SELECT * FROM sys_coupon WHERE coupon_id IN(SELECT coupon_id
FROM sys_coupon_company WHERE 1=1

AND company_id=#{companyId}

)) sc
ON sc.coupon_id = cc.coupon_id
WHERE 1 = 1

AND
(cc.receive_car_code like CONCAT('%',#{keyword},'%') )


AND
sc.oper_datetime < #{endDate}


AND
sc.oper_datetime > #{startDate}

</select>
<select id="getReportAutoCount" resultType="int">
     SELECT
        count(1)
    FROM 
    car_coupon cc
    LEFT JOIN (SELECT * FROM sys_coupon WHERE coupon_id IN(SELECT coupon_id
    FROM sys_coupon_company WHERE 1=1
    <if test="companyId !=null and companyId !=''">
        AND company_id=#{companyId}
    </if>
    )) sc
    ON sc.coupon_id = cc.coupon_id
    WHERE 1 = 1
    <if test=" endDate != null and endDate != ''">
        AND
        sc.oper_datetime &lt; #{endDate}
    </if>
    <if test=" startDate != null and startDate != ''">
        AND
        sc.oper_datetime &gt; #{startDate}
    </if>
    <if test=" keyword != null and keyword != ''">
        AND 
        (cc.receive_car_code like CONCAT('%',#{keyword},'%') )
    </if>

</select>

2个回答

a893116358
a893116358   2016.05.12 14:56
已采纳

实践是检验真理的唯一标准,调试把sql抓出来放在数据库一查不就知道了麻

caozhy
caozhy   Ds   Rxr 2016.05.12 05:22

这个要结合你的逻辑和数据库才知道,你可以根据条件拼接sql代入数据库查询下。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!