先谢谢你的帮助。我有下表:
Name | LastUpdate | Amount |
ABC | 2014-4-9 | 100 |
ABC | 2014-4-9 | **101** |
ABC | 2014-4-8 | 99 |
DEF | 2014-4-9 | **200** |
DEF | 2014-4-8 | 160 |
GHI | 2014-4-9 | **50** |
GHI | 2014-4-8 | 80 |
我的查询似乎无法获得以下结果:最新日期的金额和所有名称的最高金额之和。
上面的示例答案是351(101 + 200 + 50)。
答案 0 :(得分:1)
我将此解决方案基于
的答案find maximum of set of columns for multiple rows in mysql query
SELECT SUM(Amount) AS Total
FROM table1 AS t
WHERE LastUpdate = (SELECT MAX(LastUpdate)
FROM table1
WHERE NAme = t.Name)
AND Amount = (SELECT MAX(Amount)
FROM table1
WHERE Name = t.Name
AND LastUpdate = t.LastUpdate)