qq_34806078
qq_34806078
采纳率33.3%
2016-05-11 17:30 阅读 959
已采纳

各位大神麻烦帮忙看下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 LYY_LazySheep 2016-05-12 06:56

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

    点赞 评论 复制链接分享
  • caozhy 从今以后生命中的每一秒都属于我爱的人 2016-05-11 21:22

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

    点赞 评论 复制链接分享

相关推荐