我有一个这样的表:
Date Name Qty
2016-09-13 00:00:00 John 2
2016-09-15 00:00:00 Matt 3
2016-09-21 00:00:00 Rich 1
2016-09-23 00:00:00 Matt 1
2016-10-05 00:00:00 John 1
2016-10-07 00:00:00 Matt 3
2016-10-12 00:00:00 Rich 0
2016-10-23 00:00:00 Matt 2
如何使用 MySQL 来检索与同一月份对应的所有 Qty 值的加法并将该信息放在 View 中?
最佳答案
SELECT sum(Qty) as sum, month(date) as month, year(date) as year FROM table_name GROUP BY month(date), year(date)
会回来
sum month year
4 12 2015
10 12 2016
关于mysql - 添加同一个月内发生的值 : mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41110626/