这就是我想要实现的目标:
我有2个sql表: 交易和计划 波纹管是2个表格的结构:
交易
uid | plan | date | payid | status
------------------------------------
12 | 3 | 1388534400 | 334 | 1
699 | 4 | 1388214400 | 335 | 1
payplans:
plan | plan_price
-------------------
3 | 9.99
4 | 19.99
使用此查询:
SELECT SUM(plan_price)
FROM transations AS t
INNER JOIN payplans AS p
ON t.plan = p.plan
WHERE t.status = '1'
我能够计算所有“plan_price”行的总和, 但我想从2013年1月起每个月都有价格 例如:
jan-13 | 9.99feb-13 | 29.99 等
答案 0 :(得分:1)
对于MySQL
SELECT date_format(FROM_UNIXTIME(t.date), '%b-%y') as mnth, SUM(plan_price) FROM transations AS t INNER JOIN payplans AS p ON t.plan = p.plan WHERE t.status = '1' GROUP BY mnth;
FROM_UNIXTIME
DATE_FORMAT