<?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="com.ruoyi.web.mapper.DealInfoMapper">
    
    <resultMap type="DealInfo" id="DealInfoResult">
        <result property="id"    column="id"    />
        <result property="dh"    column="dh"    />
        <result property="amount"    column="amount"    />
        <result property="jylx"    column="jylx"    />
        <result property="jyfs"    column="jyfs"    />
        <result property="jysj"    column="jysj"    />
        <result property="jyzt"    column="jyzt"    />
    </resultMap>

    <sql id="Base_Column_List">
        id,
        dh,
        amount,
        jylx,
        jyfs,
        jysj,
        jyzt
    </sql>

    <select id="grye" resultType="string">
        select COALESCE(sum(case when szlx = '1' and jyzt = '1' then amount end),0) - COALESCE(sum(case when szlx = '2' and jyfs = '1' then amount end),0) from deal_info where user_id = #{userId}
    </select>

</mapper>