2

我有一张交易表,因为每个客户都有几笔交易,每笔交易都有积分。

我需要运行一个 mysql 查询来查找每个客户在一定时间内的积分总和。

每笔交易都有一个 CustomerID 、 Points 、 TranactionDate

问题是我只需要为日期范围在两个日期之间的交易找到 SUM(Points) GroupBY CustomerID。

像这样:

SELECT SUM(SELECT `Points` FROM `transaction` 
    WHERE Date BETWEEN '30/09/2012' AND '4/10/2012') 
    GROUP BY `CustomerID`

请我需要上述查询的等效查询。

提前致谢

4

2 回答 2

2
SELECT SUM(Points) as customerPoints FROM transaction 
    WHERE Date BETWEEN '30/09/2012' AND '4/10/2012' 
    GROUP BY CustomerID
于 2012-07-09T10:54:51.670 回答
1
SELECT `CustomerID`, SUM(`Points`) AS `Points`
FROM `transaction`
WHERE `Date` BETWEEN '30/09/2012' AND '4/10/2012'
GROUP BY `CustomerID`
于 2012-07-09T10:53:29.807 回答