-2

嘿,我有以下数据:

id       cashpayment     total payment   groupID
1        30.00              100.00           A
1        30.00              100.00           B
1        30.00              100.00           C
1        40.00              100.00           B
2        25.00              400.00           C
2        20.00              300.00           C
2        35.00              200.00           B
3        40.00              200.00           B

我想汇总 cahspayment 和总付款,结果如下所示:

id       cashpayment     total payment   
1        130.00             400.00           
2        80.00              900.00          
3        40.00               200.00      

另外,我想要同样的事情,但考虑到 groupID 所以我会得到以下

id       cashpayment     total payment   groupID
1        30.00              100.00           A
1        70.00              200.00           B
1        30.00              100.00           C
2        45.00              700.00           C
2        35.00              200.00           B
3        40.00              200.00           B

在这两种情况下,我都需要将其放入新表中

4

1 回答 1

1
select id, sum(cashpayment), sum([total payment])
from table 
group by id
order by ID

对于第一个和

   select id, sum(cashpayment), sum([total payment]), groupID
    from table 
    group by id, groupID
    order by id,groupid

第二个

于 2013-06-07T15:19:48.093 回答