基于cluase的两个条件的coloumn的总和

时间:2016-09-16 07:43:00

标签: sql-server

我有表结构

montantPayeProperty.set(montantPaye);

我必须通过Deal,AC NO分组并且还必须报告其他列,但是对于Int数量必须为两个prod类型进行总和。
我该如何实现呢?

结果

ACNo    Deal    PRODTYPE    INT AMT
100     123     OS           23
100     123     EX            7

2 个答案:

答案 0 :(得分:1)

这样的事情?

select  ACNo, 
        Deal, 
        sum([INT AMT]) as [Total INT]
from    unknowntablename
group by ACNo, Deal

你可以这样测试:

declare @table table (ACNo int, Deal int, PRODTYPE varchar(2), [INT AMT] int)

insert into @table values (100, 123, 'OS', 23)
insert into @table values (100, 123, 'EX', 7)

select  ACNo, 
        Deal, 
        sum([INT AMT]) as [Total INT]
from    @table
group by ACNo, Deal

结果将是:

ACNo   Deal   Total INT
100    123    30

答案 1 :(得分:1)

试试这个

SELECT AccNo, DEAL, SUM([INT AMT]) AS Total Amount
FROM Table
GROUP BY AccNo, DEAL