有很多商品,m种,最后入库时间不一样,有什么方法能简单实现以下结果: m种产品各自最后的入库时间.

解决方案 »

  1.   

    select *
    from tb t
    where not exists(select 1 from tb where 商品号=t.商品号 and 入库时间>t.入库时间)
      

  2.   

    如果不需要明细,可以这样
    select 商品号,max(入库时间) as 入库时间
    from tb
    group by 商品号
      

  3.   

    Select m ,Max(入库时间) From t Group By m
      

  4.   

    select
     *
    from
     tb t
    where
     入库时间=(select max(入库时间) from tb where 商品号=t.商品号 )