<?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="vip.xiaonuo.sale.mapper.SaleCustomerMapper">

    <select id="getDetail" resultType="vip.xiaonuo.sale.entity.vo.SaleCustomerVo">
        SELECT
    customer customer,
    SUM(CASE WHEN YEAR(create_time) = YEAR(CURDATE()) THEN sale_money ELSE 0 END) AS saleMoney,
    SUM(CASE WHEN YEAR(create_time) = YEAR(CURDATE()) - 1 THEN sale_money ELSE 0 END) AS lastSaleMoney
FROM sale_customer
        <if test="orgId!=null and orgId!=''">
         where  org_id = #{orgId}
        </if>
GROUP BY customer;
    </select>
</mapper>
