gpt4 book ai didi

mysql - 添加同一个月内发生的值 : mysql

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:00 24 4
gpt4 key购买 nike

我有一个这样的表:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com