用 SQL 中的结果计算每天的总数 [英] Counting total per day with my result in SQL
本文介绍了用 SQL 中的结果计算每天的总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的订单表中有 50 行/条目.我有一个列,当订单被要求时保存,名为 claimed_at
.
I have 50 rows/entrys in my table Orders. I have a column, that holds when the order is claimed at, named claimed_at
.
此字段中的日期格式如下:2011-10-03 07:07:33
The date in this field are in this format: 2011-10-03 07:07:33
这是格式(yy/mm/dd 时间).
This is in the format (yy/mm/dd time).
我还有一栏叫price
,这个price
就是他们付了多少钱.
I also have a column called price
, this price
is how much they paid.
我想显示每天的总数.
所以对于 2011-10-03 日期的 6 个订单,它应该取 6 个订单的 price
值,并将它们加在一起.
So for 6 orders from the date 2011-10-03, it should take the 6 order's price
value, and plus them together.
所以我可以显示:
2011-10-03 -- Total: 29292 Euros
2011-10-02 -- Total: 222 Euros
2011-09-28 -- Total: 4437 Euros
我该怎么做?
推荐答案
You need to use aggregate functionality of MySQL in conjuction with some DATE conversion.
SELECT DATE(claimed_at) AS day
, SUM(price) AS total
FROM Orders
GROUP BY day
这篇关于用 SQL 中的结果计算每天的总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文