查找所有在Brackendale分行贷款高于所有贷款的客户的姓名。
可以吗?

Use University;

SELECT customer_name, loan_number
FROM loan NATURAL JOIN customer
HAVING MAX(amount) > ALL (SELECT sum(loan.amount)
FROM loan
WHERE branch_name = 'Brakendale');

最佳答案

ALL是一个不需要的关键字-它什么也不做,因为它是集合的默认关键字(另一个关键字是ANY)。
ALL放在外面比较简单。但您可能希望其中有一个组并删除loan_number,否则每一行都必须在其自己的组中。
我觉得这个问题更有意义:

SELECT customer_name, MAX(amount)
FROM loan
NATURAL JOIN customer
GROUP BY customer_name
HAVING MAX(amount) > (
  SELECT sum(loan.amount)
  FROM loan
  WHERE branch_name = 'Brakendale');

关于mysql - 比所有人更大,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14059979/

10-09 15:55