分享一个子查询的mybatis动态sql

<select id="statisticalHallProfit"  parameterType="UsGameRecordDetailQuery" resultType="java.util.HashMap">
      select a.game_type,(SELECT SUM(amount) from us_game_record_detail
      where win_loss="0"
      <if test="openCardTime != null">
          and open_card_time &gt;= #{openCardTime,jdbcType=TIMESTAMP}
      </if>
      <if test="openCardTime1 != null">
          and open_card_time &lt;= #{openCardTime1,jdbcType=TIMESTAMP}
      </if>) c,
      (SELECT SUM(amount) from us_game_record_detail
      where win_loss="1"
      <if test="openCardTime != null">
          and open_card_time &gt;= #{openCardTime,jdbcType=TIMESTAMP}
      </if>
      <if test="openCardTime1 != null">
          and open_card_time &lt;= #{openCardTime1,jdbcType=TIMESTAMP}
      </if>) d,
      (SELECT SUM(amount) from us_game_record_detail
      where win_loss="0"
      <if test="openCardTime != null">
          and open_card_time &gt;= #{openCardTime,jdbcType=TIMESTAMP}
      </if>
      <if test="openCardTime1 != null">
          and open_card_time &lt;= #{openCardTime1,jdbcType=TIMESTAMP}
      </if>)-(SELECT SUM(amount) from us_game_record_detail
      where win_loss="1"
      <if test="openCardTime != null">
          and open_card_time &gt;= #{openCardTime,jdbcType=TIMESTAMP}
      </if>
      <if test="openCardTime1 != null">
          and open_card_time &lt;= #{openCardTime1,jdbcType=TIMESTAMP}
      </if>) e
      from us_game_record_detail  b
      LEFT JOIN us_game_record a on a.game_record_id=b.game_record_id
      where a.site_type="2"
      group by a.game_type
  </select>
发布了237 篇原创文章 · 获赞 235 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/LRXmrlirixing/article/details/100039258