mysql表
Name | Amount
------------
name1 | 150
name1 | 90
name2 | 100
name2 | 110
name3 | 10
结果需要类似的东西
Name | SUM(Amount)
------------
name1 | 240
name2 | 210
试过了
SELECT Name, SUM(Amount)
WHERE Amount < 210 AND SUM(Amount) >= 210
GROUP BY Name
但得到错误SQLSTATE[HY000]: General error: 1111 Invalid use of group function
如果我删除AND SUM(Amount) >= 210
代码有效
试着想......我是否需要一开始就SUM(Amount) AS SumAmount
在同一个查询中获取和使用而不是AND SUM(Amount) >= 210
使用AND SumAmount >= 210
?...但是SELECT
二合一查询...
就像是 ?
SELECT SUM(Amount) AS SumAmount
WHERE Amount < 210
GROUP BY Name
SELECT Name, SUM(Amount)
WHERE SumAmount >= 210
GROUP BY Name
请指教