A
A
avtorlego2019-01-07 19:17:25
SQL
avtorlego, 2019-01-07 19:17:25

How to get the biggest value based on 2 columns?

I get users with the largest balance like this:

SELECT * FROM balances ORDER BY balance DESC LIMIT 10;

How to get data from balances but based on 2 columns. Tipo I need to get the largest numbers based on the sum of the balances of their 2 tables. Namely from bank.balances and balances.balance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-01-07
@tsklab

Bind by user code and fold.

Can you give more details?
Is it possible to do something else to give the user code?
SELECT balances.[КодПользователя],
       ( bank.balances + balances.balance ) AS balances 
  FROM balances
    JOIN bank ON bank.[КодПользователя] = balances.[КодПользователя]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question