我有以下 SQL:
SELECT
t.amount
FROM
transactions t
JOIN contracts c ON t.contractId = c.id
JOIN insertions i ON c.id = i.contractId
JOIN magazines m ON i.magazineId = m.id
WHERE m.id = 26
AND t.isChargedBack IS FALSE
AND t.`timestamp` >= '2013-09-12'
AND t.`timestamp` <= date_add('2013-09-12',interval 1 month)
GROUP BY
t.id;
产生:
1100
800
1025
500
1200
552
395
395
1170
1000
675
我只想要这个结果的总和。我预计8812。
所以我使用以下 SQL:
SELECT
IFNULL(SUM(t.amount),0)
FROM
transactions t
JOIN contracts c ON t.contractId = c.id
JOIN insertions i ON c.id = i.contractId
JOIN magazines m ON i.magazineId = m.id
WHERE m.id = 26
AND t.isChargedBack IS FALSE
AND t.`timestamp` >= '2013-09-12'
AND t.`timestamp` <= date_add('2013-09-12',interval 1 month)
GROUP BY
t.id;
这是我的结果:
39600
9600
61500
9000
43200
49680
14220
5925
7020
36000
72900
???