重複の可能性:
mysql: GROUP BY 内で LIMIT を使用して、グループごとに N 個の結果を取得しますか?
私は次のデータを持っています。
id val
smith 20
smith 10
smith 8
smith 30
jones 40
jones 10
jones 30
jones 30
私が望むのは、ID でグループ化し、各 ID の 2 つの最大値を合計することです。
smith 50 from 30+20
jones 70 from 40+30
ありがとう。