<?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.czg.service.product.mapper.ShopStorageMapper">

    <select id="countRecord" resultType="com.czg.product.dto.storage.CountStorageDTO">
        SELECT name,
               img_url AS imgUrl,
               SUM(CASE WHEN status = 1 THEN num ELSE 0 END) as savNum,
               SUM(CASE WHEN status = 2 THEN num ELSE 0 END) as expNum
        FROM tb_shop_storage
        WHERE shop_id=#{shopId}
        GROUP BY name
        ORDER BY SUM(CASE WHEN status = 1 THEN num ELSE 0 END) desc
    </select>
</mapper>
