sql -- 获取商品分类的最新销售情况

表设计:

需求:

1.先找出各个分类中销售的最新日期

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

2.根据日期和分类去匹配数据

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;

posted @ 2019-07-16 14:56  花花妹子。  阅读(391)  评论(0编辑  收藏  举报