为什么此代码有效:
SELECT year, sum(value)
FROM test
GROUP BY year
这不是吗?
SELECT year, sum(value)
FROM test
GROUP BY year
WHERE `user` = 1
答案 0 :(得分:7)
GROUP BY
需要在WHERE
之后:
SELECT year, sum(value) FROM test WHERE user = 1 GROUP BY year
答案 1 :(得分:1)
你试过吗
SELECT year, sum(value) FROM test WHERE user = 1 GROUP BY year
答案 2 :(得分:1)
我不是专家,但尝试“HAVING”条款:
SELECT year, sum(value)
FROM test
GROUP BY year
having `user` = 1
答案 3 :(得分:0)
反转GROUP BY
和WHERE
条款:
SELECT year, SUM(value)
FROM test
WHERE user = 1
GROUP BY year