sql -- 獲取商品分類的最新銷售狀況

表設計:spa

需求:設計

1.先找出各個分類中銷售的最新日期code

select prod_class,max(sales_date) as sn from prod_sales group by prod_class

2.根據日期和分類去匹配數據blog

select a.*
from prod_sales a
         inner join (
    select prod_class, max(sales_date) as sn from prod_sales group by prod_class) b
                    on a.prod_class = b.prod_class and a.sales_date = b.sn;

相關文章
相關標籤/搜索