如何获得正确的'customerNumber'?

时间:2014-03-10 16:32:16

标签: mysql sql

我现在需要取出正确的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

1 个答案:

答案 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

试试。