表字段ID      NAME     TIME    AMOUNT14502   1111     0201    1
14502   1111     0201    5
14502   2222     0201    4
14502   1111     0201    2
14502   2222     0201    3
14502   1111     0201    2
14502   2222     0201    5
14502   1111     0201    2
14502   1111     0202    3
14502   1111     0202    1
14502   1111     0202    2想取出不同的ID      NAME     TIME 的最大的AMOUNT值。

ID      NAME     TIME    AMOUNT
14502   1111     0201    5
14502   2222     0201    5
14502   1111     0202    3可是我写的句子
max group by 不对 max partition by 也不对、、谢谢帮助~!

解决方案 »

  1.   

    select ID, NAME  ,TIME,max(amount) amount
    from table
    group by ID, NAME  ,TIME
      

  2.   

    with test as
    (
    select 14502 a,  1111 b,    '0201' c,    1 d from dual
    union all
    select 14502,   1111,    '0201',    5  from dual
    union all 
    select 14502,   2222,    '0201',    4   from dual
    union all
    select 14502,   1111,    '0201',    2   from dual
    union all
    select 14502,   2222,    '0201',    3  from dual
    union all 
    select 14502,   1111,    '0201',    2  from dual
    union all 
    select 14502,   2222,    '0201',    5  from dual
    union all 
    select 14502,   1111,    '0201',    2  from dual
    union all 
    select 14502,   1111,    '0202',    3  from dual
    union all 
    select 14502,   1111,    '0202',    1  from dual
    union all 
    select 14502,   1111,    '0202',   2  from dual
    )
    select a,b,c,max(d) from test
    group by c,b,a
    order by c,b,a
    --result:14502 1111 0201 5
    14502 2222 0201 5
    14502 1111 0202 3
      

  3.   

    我错误的最大值总是9我在想  是不是我的格式没有定义对 现在的AMOUNT的格式是VARCHAR2是不是要转换成NUMBER
      

  4.   

    SELECT ID,NAME,TIME,MAX(amount) FROM test t GROUP BY ID,NAME,TIME;