【发布时间】:2015-02-26 13:17:43
【问题描述】:
感谢您查看我的问题。
我正在尝试通过 mysql 按日期时间对小计列和分组求和。我必须在求和之前加入两个表。
我的第一个表 Payments 包含以下数据:
ID | User_ID | Order_ID | Subtotal | Tax | Tip | Discount | Total | Payment_Method | Payment_Collected
12 | 123 | 76 | 10.99 | 0.99| 1 | 0.00 | 12.98 | Cash | 1
我的第二个表 Order 包含以下数据:
ID | User_ID | Address_ID | orderplaced_ts | order_status
76 | 23 | 123 | 2015-02-26 12:23:41 |
我尝试运行的查询如下:
select `order`.orderplaced_ts, SUM(`payments`.subtotal) as Subtotal
from `payments`
join `order` on `order`.id=`payments`.order_id
where `order`.order_status != "Cancelled"
and `payments`.payment_collected = 1
group by `order`.orderplaced_ts
我想要实现的是获取所有小计的总和并按相同的日期时间分组。示例输出为:
orderplaced_ts | Subtotal
2015-02-20 | 123.12
2015-02-21 | 223.12
2015-02-22 | 124.25
2015-02-23 | 247.23
2015-02-24 | 623.50
我当前的查询输出是:
orderplaced_ts | Subtotal
2015-02-20 05:56:23 | 123.12
2015-02-20 06:36:23 | 123.12
2015-02-20 06:38:23 | 123.12
有人可以指出为什么我的查询没有给我想要的输出的正确方向吗?
【问题讨论】: