mysql where子句给我一个错误
基本上我有上面显示的数据库。我想得到每个月的总数,但具体年份除外 当我使用这个查询时,它可以工作,但它不会只给出特定的年份,因为我没有指定年份mysql where子句给我一个错误,mysql,sql,group-by,where-clause,Mysql,Sql,Group By,Where Clause,基本上我有上面显示的数据库。我想得到每个月的总数,但具体年份除外 当我使用这个查询时,它可以工作,但它不会只给出特定的年份,因为我没有指定年份 | iID | saleID | cusID | date | total | discount | advance | paid_status | +-----+--------+-------+------------+-------+----------+---------+-------------+ | 16 | 1
| 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 |
但是当我使用where子句时,比如following,它不起作用,给我一个错误
SELECT sum(total) FROM `invoice_reg` group by month(date) ;
我也试过这个,但费尔德也是
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
任何帮助都将不胜感激尝试将
group by
语句移动到命令末尾尝试将group by
语句移动到命令末尾尝试将group by
语句移动到命令末尾命令请在分组依据
请在
分组依据之前使用where
请在分组依据之前使用where
请在分组依据之前使用where
你可以这样试试
check the manual that corresponds to your MySQL server version for the right syntax to use near 'where YEAR(date) = 2014
你可以这样试试
check the manual that corresponds to your MySQL server version for the right syntax to use near 'where YEAR(date) = 2014
你可以这样试试
check the manual that corresponds to your MySQL server version for the right syntax to use near 'where YEAR(date) = 2014
你可以这样试试
check the manual that corresponds to your MySQL server version for the right syntax to use near 'where YEAR(date) = 2014
试试这个:
SELECT sum(total) FROM `invoice_reg`
where YEAR(date) = year(now())
group by month(date)
试试这个:
SELECT sum(total) FROM `invoice_reg`
where YEAR(date) = year(now())
group by month(date)
试试这个:
SELECT sum(total) FROM `invoice_reg`
where YEAR(date) = year(now())
group by month(date)
试试这个:
SELECT sum(total) FROM `invoice_reg`
where YEAR(date) = year(now())
group by month(date)
为什么不先使用google呢?不确定功能需求,但是语法错误是因为在GROUPBY子句之后指定了where子句,这是不正确的。group by子句总是跟在where子句后面。@Abhi我使用了谷歌,这就是我在不了解MySQL的情况下进行上述查询的方式。这可能是您要查找的查询的正确版本。我还没有测试过,查询SELECT month(date),sum(total)FROMinvoice\u reg
where YEAR(date)=2014 group by month(date)为什么不先使用google?不确定功能要求,但语法错误是因为在group by子句之后指定了where子句,这是不正确的。group by子句总是跟在where子句后面。@Abhi我使用了谷歌,这就是我在不了解MySQL的情况下进行上述查询的方式。这可能是您要查找的查询的正确版本。我还没有测试过,查询SELECT month(date),sum(total)FROMinvoice\u reg
where YEAR(date)=2014 group by month(date)为什么不先使用google?不确定功能要求,但语法错误是因为在group by子句之后指定了where子句,这是不正确的。group by子句总是跟在where子句后面。@Abhi我使用了谷歌,这就是我在不了解MySQL的情况下进行上述查询的方式。这可能是您要查找的查询的正确版本。我还没有测试过,查询SELECT month(date),sum(total)FROMinvoice\u reg
where YEAR(date)=2014 group by month(date)为什么不先使用google?不确定功能要求,但语法错误是因为在group by子句之后指定了where子句,这是不正确的。group by子句总是跟在where子句后面。@Abhi我使用了谷歌,这就是我在不了解MySQL的情况下进行上述查询的方式。这可能是您要查找的查询的正确版本。我还没有测试过,查询选择月份(日期),从invoice\u reg
where YEAR(date)=2014年按月分组(日期)