idx         类别                                                 金额          
----------- -------------------------------------------------- ----------- 
1           asp                                                10
1           asp                                                15
3           php                                                8
4           sql                                                22有这样的一个表我怎么样才能合并成下面这样呢
idx         类别                                                 金额          
----------- -------------------------------------------------- ----------- 
1           asp                                                25
3           php                                                8
4           sql                                                22

解决方案 »

  1.   

    select idx, 类别,金额 = sum(金额) from 表 group by idx, 类别
      

  2.   

    select idx, 类别,金额 = sum(金额) 
    from 表 
    group by idx, 类别
      

  3.   

    --呵呵
    select idx, 类别, 金额 = sum(金额) from 表 group by idx, 類別
      

  4.   

    或一种写法:
    select 
    idx, 
    类别,
    金额 = (select sum(金额) from 表 where idx=t.idx and 类别=t.类别)
    from 
    表 t
    group by 
    idx, 类别
      

  5.   


    select 
       idx,   
       类别,
       sum(金额)金额
    from 表
    group by 
       idx,   
       类别
      

  6.   

    select idx, 类别,sum(金额) 金额 
    from 表 
    group by idx, 类别
      

  7.   

    select idx,类别,sum(金额) from tb group by idx,类别
      

  8.   

    select idx, 类别,金额 = sum(金额) from 表 group by idx, 类别
      

  9.   

    select idx,类别,sum(金额) from tb group by idx,类别
      

  10.   

    select   idx,   类别,金额   =   sum(金额)   from   表   group   by   idx,   类别
      

  11.   

    SElect idx,类别,sum(金额) 金额 from 表 group by idx,类别