0

我有一个有 3 列的表:客户、账单日期、消费

CITY - PARKS/6TH AVE BMX PARK   2013-04-29 00:00:00.000 0
CITY - PARKS/6TH AVE BMX PARK   2013-04-29 00:00:00.000 30
CITY - PARKS/6TH AVE BMX PARK   2013-05-30 00:00:00.000 0
CITY - PARKS/6TH AVE BMX PARK   2013-05-30 00:00:00.000 19500
CITY - PARKS/6TH AVE BMX PARK   2013-06-28 00:00:00.000 0
CITY - PARKS/6TH AVE BMX PARK   2013-06-28 00:00:00.000 42100
CITY - FIRE STATION #3  2012-11-27 00:00:00.000 0
CITY - FIRE STATION #3  2012-11-27 00:00:00.000 8900
CITY - FIRE STATION #3  2012-12-27 00:00:00.000 0
CITY - FIRE STATION #3  2012-12-27 00:00:00.000 7900
CITY - FIRE STATION #3  2013-01-28 00:00:00.000 0
CITY - FIRE STATION #3  2013-01-28 00:00:00.000 3090
CITY - FIRE STATION #3  2013-01-28 00:00:00.000 7210
CITY - FIRE STATION #3  2013-02-28 00:00:00.000 0
CITY - FIRE STATION #3  2013-02-28 00:00:00.000 10100
CITY - FIRE STATION #3  2013-03-29 00:00:00.000 0
CITY - FIRE STATION #3  2013-03-29 00:00:00.000 6700
CITY - FIRE STATION #3  2013-04-29 00:00:00.000 0
CITY - FIRE STATION #3  2013-04-29 00:00:00.000 9100
CITY - FIRE STATION #3  2013-05-30 00:00:00.000 0
CITY - FIRE STATION #3  2013-05-30 00:00:00.000 11100
CITY - FIRE STATION #3  2013-06-28 00:00:00.000 0
CITY - FIRE STATION #3  2013-06-28 00:00:00.000 12700
CITY - FIRE STATION #3  2012-07-27 00:00:00.000 0
CITY - FIRE STATION #3  2012-08-27 00:00:00.000 0
CITY - FIRE STATION #3  2012-08-27 00:00:00.000 1630
CITY - FIRE STATION #3  2012-09-28 00:00:00.000 0

由于我对同一个客户有相同的 BillingDate,我想根据匹配的 BillingDate 来总结消费。这应该给我以下信息:

CITY - PARKS/6TH AVE BMX PARK   2013-04-29 00:00:00.000 30
CITY - PARKS/6TH AVE BMX PARK   2013-05-30 00:00:00.000 19500
CITY - PARKS/6TH AVE BMX PARK   2013-06-28 00:00:00.000 42100
CITY - FIRE STATION #3  2012-11-27 00:00:00.000 8900

等等....

我发布了一个类似的问题,但我真的没有得到我想要的东西。谢谢SQL专家。

4

2 回答 2

2

如果我没有错过什么

select Customers, BillingDate, sum(Consumption)
from Table1
group by Customers, BillingDate
于 2013-08-12T18:42:53.320 回答
2

它会是这样的:

Select
Customers, BillingDate, sum(Consumption)
from [Table]
group by Customers, BillingDate
于 2013-08-12T18:43:27.040 回答