1

为什么此代码有效:

SELECT year, sum(value)
FROM test
GROUP BY year

这不是吗?

SELECT year, sum(value)
FROM test
GROUP BY year
WHERE `user` = 1
4

4 回答 4

7

GROUP BY需要紧随其后WHERE

SELECT year, sum(value) FROM test WHERE user = 1 GROUP BY year 
于 2012-12-20T16:55:23.077 回答
1

你有没有尝试过

 SELECT year, sum(value) FROM test WHERE user = 1 GROUP BY year

?

于 2012-12-20T16:55:56.590 回答
1

我不是专家,但请尝试“HAVING”子句:

SELECT year, sum(value)
FROM test
GROUP BY year
having `user` = 1
于 2012-12-20T16:59:55.390 回答
0

反转GROUP BYWHERE子句:

SELECT year, SUM(value)
  FROM test
 WHERE user = 1
 GROUP BY year
于 2012-12-20T16:55:51.473 回答