gpt4 book ai didi

mysql where 子句给我一个错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:07:14 25 4
gpt4 key购买 nike

| iID | saleID | cusID | date       | total | discount | advance | paid_status |

+-----+--------+-------+------------+-------+----------+---------+-------------+

| 16 | 1 | 1 | 2014-01-17 | 2400 | 100 | 1000 | 1 |

| 17 | 1 | 1 | 2014-02-17 | 240 | 100 | 1000 | 1 |

| 18 | 1 | 1 | 2013-03-17 | 280 | 100 | 1000 | 1 |

| 19 | 1 | 1 | 2014-04-18 | 120 | 100 | 1000 | 1 |

基本上我有上面显示的数据库。我想获得除特定年份之外的每个月的总和

当我使用这个查询时,它可以工作,但它不会只给出特定年份,因为我没有指定年份

SELECT sum(total) FROM `invoice_reg` group by month(date) ;

但是当我使用像下面这样的where子句时它不起作用给我一个错误

SELECT sum(total) FROM `invoice_reg` group by month(date) where YEAR(date) = 2014

我也试过这个。但也失败了

SELECT sum(total) FROM `invoice_reg` group by month(date) where DATE_FORMAT(date,'%Y')=2014

这是我遇到的错误

check the manual that corresponds to your MySQL server version for the right syntax to use near 'where YEAR(date) = 2014

任何帮助将不胜感激

最佳答案

尝试将 group by 语句移动到命令的末尾

关于mysql where 子句给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25948019/

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