package com.ruoyi.zhushi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.zhushi.entity.ProductRanking;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductRankingMapper extends BaseMapper<ProductRanking> {

    @Select("SELECT * FROM productranking pr " +
            "INNER JOIN ( " +
            "    SELECT sn, shop, MAX(createdate) as max_createdate " +
            "    FROM productranking " +
            "    WHERE website = #{website} and category= #{category} " +
            "    GROUP BY sn, shop " +
            ") latest " +
            "ON pr.sn = latest.sn AND pr.shop = latest.shop AND pr.createdate = latest.max_createdate " +
            "WHERE pr.website = #{website} and category= #{category}")
    List<ProductRanking> getProductRankingListCurrent(@Param("website") Integer website,@Param("c") String category);
}
