分享一个子查询的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>

 

posted @ 2022-08-11 18:49  码海兴辰  阅读(27)  评论(0)    收藏  举报