0

i have a table as following:

Account(Acc_number,Acc_balance,branch_code)

Now i want to list all account details in each branch with the highest balance, how should I write the sql statement?

Simply said, i just want to list out all the branches, with the account of having highest balance.

Ollie
  • 17,058
  • 7
  • 48
  • 59
C PWL
  • 519
  • 6
  • 10
  • 26

1 Answers1

2

There are similar questions.

You can use analytic functions.

Try this if it works for you:

    select branch_code,acc_number,acc_balance from
(
        select distinct acc_number,branch_code,acc_balance, 
        max(acc_balance) over(partition by branch_code order by 1) as MAX 
        from Account
)

    where acc_balance=MAX
Community
  • 1
  • 1
bonsvr
  • 2,262
  • 5
  • 22
  • 33