我现在需要取出正确的customerNumber,但它会给我找到它找到的第一个客户编号。
SELECT temp.customerNumber, MAX( temp.sum ) AS max
FROM (
SELECT p.customerNumber, SUM( p.amount ) AS sum
FROM payments p
GROUP BY p.customerNumber
) AS temp
答案 0 :(得分:0)
SELECT temp.customerNumber, MAX( temp.tsum ) AS tmax
FROM (
SELECT p.customerNumber, SUM( p.amount ) AS tsum
FROM payments p
GROUP BY p.customerNumber ) AS temp
GROUP BY temp.customerNumber
试试。