使用此查询:
SELECT
fulfilled_at,
ROUND(SUM(adjusted_total_charge), 2) as val,
WEEK(fulfilled_at) as week
FROM purchases
WHERE fulfilled_at >= '2013-02-23 16:59:54 -0500'
AND fulfilled_at <= '2013-05-22 16:59:54 -0400'
GROUP BY YEAR(fulfilled_at), WEEKOFYEAR(fulfilled_at)
ORDER BY fulfilled_at ASC
我得到这个结果:
2013-02-24 14:03:29 5570.00 8
2013-02-27 04:15:46 67354.25 8
2013-03-05 13:53:28 45298.00 9
2013-03-11 13:54:59 40751.80 10
2013-03-18 16:12:27 42863.25 11
2013-03-27 14:16:25 35449.45 12
2013-04-02 13:23:58 46326.75 13
2013-04-08 05:25:55 35905.45 14
2013-04-15 15:50:12 28910.19 15
2013-04-22 18:42:10 31960.00 16
2013-04-29 23:37:51 36610.10 17
2013-05-06 15:57:23 24511.40 18
2013-05-16 22:32:29 20675.20 19
2013-05-20 18:17:49 9343.00 20
请注意,显示的 fulfilled_at 不是来自一周中的特定日期,因此间隔不是偶数 7 天。我希望日期相隔 7 天,最好从每周的星期一开始。