<?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.snack.server.module.product.mapper.ProductMapper">

    <!--
        批量查询商品的 SKU 起售价（最低价格）
        用于商品列表"¥XX 起"展示
    -->
    <select id="selectMinPriceByProductIds" resultType="java.util.Map">
        SELECT
            product_id AS productId,
            MIN(price)  AS minPrice,
            SUM(stock)  AS totalStock
        FROM product_sku
        WHERE product_id IN
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY product_id
    </select>

</mapper>
