AccountItemID  CurrencyID  Amount
     12             2         10
     12             2         20
     12             3         10
怎么可以输出以下结果AccountItemID  CurrencyID  Amount
     12             2         30
     12             3         10

解决方案 »

  1.   

    select AccountItemID,CurrencyID,sum(Amount) from xxx group by AccountItemID,CurrencyID
      

  2.   

    SQL Server下应该是这样,MySQL不清楚,应该意思差不多吧
      

  3.   

    select AccountItemID,CurrencyID,sum(Amount) as Amount from table1 group by AccountItemID,CurrencyID;
      

  4.   

    select AccountItemID,CurrencyID,sum(Amount) Amount  from table group by AccountItemID,CurrencyID
    肯定没有问题了
      

  5.   

    create table aa (AccountItemID int(11),  CurrencyID int(11),  Amount int(11)) engine=innodb charset=utf8;
    insert into aa values('12','2','10'),('12','2','20'),('12','3','10');
    select AccountItemID,CurrencyID,sum(Amount) from aa group by AccountItemID,CurrencyID;
    ================query result(2 records)
    AccountItemID CurrencyID sum(Amount) 
    12 2 30 
    12 3 10 
      

  6.   

    select AccountItemID,CurrencyID,sum(Amount) as Amount
    from 表名
    group by AccountItemID,CurrencyID