为什么这会给我错误的customerNumber? [英] why does this give me the wrong customerNumber?
本文介绍了为什么这会给我错误的customerNumber?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让支付最高金额的客户.它给了我最大的数量,但给了错误的客户.我该怎么办?
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( temp.max ) AS sum
FROM (
SELECT p.customerNumber, p.amount AS max
FROM payments p
GROUP BY p.customerNumber
) AS temp
推荐答案
使用联接,可能如下:-
Using a join, possibly as follows:-
SELECT *
FROM payments
INNER JOIN
(
SELECT MAX(amount) AS MaxAmount
FROM payments
) Sub1
ON payments.amount = Sub1.MaxAmount
不利的一面是,如果两个人都支付了相同的高额费用,那么两个人都将被退回.
Down side of this is that if 2 people both have the same high payment then both will be returned.
这篇关于为什么这会给我错误的customerNumber?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文