1

我有多个表需要合并为一个。

SELECT name, SUM(money) AS MONEY FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
GROUP BY name

输出是人名(第一列)和人的钱(第二列)。

name | money
aaron  1220
mike   800
john   200
kate   600

现在我尝试按金额过滤结果,即为“Sum(money) > 500”的人显示结果

出于这个原因,我尝试输入“WHERE money > 500 GROUP BY name”,但输出错误(aaron 1000、mike 610 等)。

您如何编写查询来过滤最后/结束结果?

4

2 回答 2

4
Group By Name
having sum(money) > 500

编辑:“最后/最终结果”是什么意思?

于 2012-04-07T10:07:27.930 回答
4

如果你想得到SUM(money)大于 500 的值,那么你可以这样做:

SELECT name, SUM(money) AS MONEY FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
GROUP BY name
HAVING SUM(money)>500
于 2012-04-07T10:09:31.043 回答