<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="cn.pluss.platform.mapper.UserAccountFlowMapper">

    <select id="selectSumByUserId" resultType="java.math.BigDecimal">
        SELECT
        IFNULL( SUM( amount ), 0 ) - (
        SELECT
        IFNULL( SUM( amount ), 0 )
        FROM
        tb_pluss_user_account_flow
        WHERE
        user_id = #{userId}
        AND biz_code = '103'
        AND create_time &lt; #{endTime} AND create_time > #{startTime}
        )
        FROM
        tb_pluss_user_account_flow
        WHERE
        user_id = #{userId}
        AND biz_code IN ( '102', 'LD' )
        AND create_time &lt;#{endTime} AND create_time > #{startTime}
    </select>
</mapper>