I tried to get the customer that pay the maximum amount. It gave me the maximum amount but the wrong customer. what should i do?
SELECT temp.customerNumber, MAX
Consider that your subselect will return something like
customerNumber amount
1 100
2 200
Then the outer query will pull up those customer numbers and the MAX of ALL the rows, which breaks the link between customer numbers and their respective amounts. You're forcing the LARGES amount from ALL of the groups to be applied to all of the groups:
cN amount
1 200
2 200