List record from table by selects MAX value
i have a table as following:
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.
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