id   type   num
1     a      1
2     a      3
3     a      6
4     b      1
5     b      3
6     b      6想新增一行,得到type A 的最大值加上type B的最大值,即id   type  num
100    c    12

解决方案 »

  1.   

    insert into table1 
    select 100,'c' ,
      (select max(num) from table1 where type='A')+(select max(num) 
    from table1 where type='B') from table1 
      

  2.   

    是这样的,表中type=a的最大值为6
                type=b的最大值为6
             想得到12这个值
      

  3.   

    insert into table1 
    select 100,'c' ,
      (select max(num) from table1 where type='A')+(select max(num) from table1 where type='B') 
    from table1 
      

  4.   

    oraclelogan type的类型不确定,不能写死
      

  5.   

    如果type有很多,怎么办?上面的语句只是得到max(a)+max(b)
      

  6.   

    INSERT INTO YOURTABLE (SELECT 100,'c' ,
    SUM(MAX(num)) FROM YOURTABLE GROUP BY TYPE)
      

  7.   

    如果想得到type中id最大的值相加该怎么办?
      

  8.   


    下面这种情况喃?谢谢!
    id  type  num   num1
    1    a      1    1
    2    a      3    3
    3    a      6    6
    4    b      1    1
    5    b      3    3
    6    b      6    6想新增一行,得到type  中的最大id的num,num1相加,即 id  type  num   num1
    100    c    12   12
      

  9.   

    INSERT INTO YOURTABLE (SELECT 100,'C',NUM+NUM1 AS NUM,NUM+NUM1 AS NUM1 FROM YOURTABLE WHERE ID=(SELECT MAX(ID) FROM YOURTABLE))
      

  10.   

    insert into yourtable 
    select 100,',c', select sum(maxnum ) from (select type,max(num) maxnum from yourtable group by type) from dual
      

  11.   

    insert into table1 select '100','c',sum(num) from (select max(num) as num from table1 group by type)