Sql 如何对按客户分组的多个列和行求和
我试图得到一个最终列,将所有感兴趣的列相加为一个最终数字,这样每个客户都有一个数字。我目前有:Sql 如何对按客户分组的多个列和行求和,sql,ms-access,group-by,vba,ms-access-2010,Sql,Ms Access,Group By,Vba,Ms Access 2010,我试图得到一个最终列,将所有感兴趣的列相加为一个最终数字,这样每个客户都有一个数字。我目前有: +--------+--------+-------+-------+-------+-------+ |Customer|Number |IntMax |IntMin |IntMin1|IntMax1| +--------+--------+-------+-------+-------+-------+ |Jones |72352516|$0.00 |$381.47|$0.00 |$0.
+--------+--------+-------+-------+-------+-------+
|Customer|Number |IntMax |IntMin |IntMin1|IntMax1|
+--------+--------+-------+-------+-------+-------+
|Jones |72352516|$0.00 |$381.47|$0.00 |$0.00 |
+--------+--------+-------+-------+-------+-------+
|Jones |72352516|$455.31|$0.00 |$0.00 |$0.00 |
+--------+--------+-------+-------+-------+-------+
|Brett |70920356|$0.00 |$0.00 |$194.56|$129.71|
+--------+--------+-------+-------+-------+-------+
|Gavin |79023561|$0.00 |$617.29|$0.00 |$0.00 |
+--------+--------+-------+-------+-------+-------+
|Gavin |79023561|$531.46|$0.00 |$0.00 |$0.00 |
+--------+--------+-------+-------+-------+-------+
我希望看到的结果是:
+--------+--------+---------+
|Customer|Number |IntFinal |
+--------+--------+---------+
|Jones |72352516|$836.78 |
+--------+--------+---------+
|Brett |70920356|$324.27 |
+--------+--------+---------+
|Gavin |79023561|$1,148.76|
+--------+--------+---------+
非常感谢
SELECT Customer, Number,
SUM(IntMax + IntMin + IntMin1 + IntMax1) AS IntFinal
FROM Table1
GROUP BY Customer, Number
输出:
| CUSTOMER | NUMBER | INTFINAL |
|----------|----------|----------|
| Brett | 70920356 | 324.27 |
| Jones | 72352516 | 836.78 |
| Gavin | 79023561 | 1148.75 |
这里是演示谢谢大家的回答,伙计们-我最后也找到了以下答案: 选择利息\最小\最大值1.Customer,CCurSum[IntMax]+Sum[IntMin]+Sum[IntMax1]+Sum[IntMin1]作为总计 来自表1 按利息分组\u Min\u Max1.Customer、利息分组\u Min\u Max1.Number
<!-- language: lang-sql -->
SELECT Customer,Number,SUM((IntMax+IntMin+IntMin1+IntMax1)) as IntFinal
FROM tablename
GROUP BY Customer,Number
create table #temp
(
Customer varchar(12) not null,
Number int not null,
IntMax decimal(19,6),
IntMin decimal(19,6),
IntMin1 decimal(19,6),
IntMax1 decimal(19,6),
)
insert into #temp values('Jones',72352516,'0.00','381.47','0.00','0.00')
insert into #temp values('Jones',72352516,'455.31','0.00','0.00','0.00')
insert into #temp values('Brett',70920356,'0.00','0.00','194.56','129.71')
insert into #temp values('Gavin',79023561,'0.00','617.29','0.00','0.00')
insert into #temp values('Gavin',79023561,'531.46','0.00','0.00','0.00')
select * from #temp
select t1.Customer, t1.Number, SUM(T1.IntMax+t1.IntMax1+t1.IntMin+t1.IntMin1) as IntFinal from #temp t1 group by t1.Customer, t1.Number
drop table #temp