有一个表supply_test
——————————————
name       有一个表supply_test
——————————————
name            公司名
type            物资类型
time            日期
stock_quan      库存量我想要,每一个公司的每一种物资,最近一个日期的库存量,应该怎么写??

解决方案 »

  1.   

     select name,type,stock_quan from(select name,type,stock_quan ,row_number() over (group by name,type order by time desc) num from supply_test )t where t.num=1
      

  2.   

    select name as 公司名,
           type as 物资类型,
           stock_quan as 库存量,
           max(time) as 日期
      from supply_test
     group by name, type, stock_quan可以这样吗?
      

  3.   

    错了是partition by
    select name,type,stock_quan from(select name,type,stock_quan ,row_number() over (partition by name,type order by time desc) num from supply_test )t where t.num=1
      

  4.   


    简单问题搞复杂了吧.
    基本sql就可以了。
    SELECT NAME, TYPE, sum(STOCK_QUAN) xx
      FROM SUPPLY_TEST 
     WHERE T.time between sysdate-10 and sysdate;