在表格中添加线索并显示最高的vsalue

时间:2015-09-26 01:58:52

标签: mysql

我有两张桌子

 account
 account_number     balance
 -------------      --------

 depositor
 account_number     name
 --------------     ----

需要做的是显示最高帐户的名称和值。我使用以下语句在一个地方获取所有名称和帐户值。

  

select ACCount.balance, depositor.customer_name
2  from account
3  inner join depositor
4  on account.account_number = depositor.account_number;

BALANCE CUSTOMER_NAME
---------- ---------------
   500 customer1
   400 customer1
   500 customer2
   900 customer2
  6250 customer2
  7500 customer3
100000 customer4

但我仍然坚持获得SUM(余额)以及显示最高帐户。

2 个答案:

答案 0 :(得分:0)

您需要if charge_user(@order_form.order) redirect_to root_path, notice: "Thank you for placing the order." else # rest of the code end group byorder by

limit

答案 1 :(得分:0)

  

如果您需要前1,2,3等,请使用限制1,2,3。喜欢(限制1

select sum(account.balance) as totalbalance, depositor.customer_name from account inner join depositor on account.account_number = depositor.account_number group by depositor.customer_name order by totalbalance desc;