D
D
Docaram2020-04-27 22:58:58
SQL
Docaram, 2020-04-27 22:58:58

How to display TOP buyers from a SQL database with a query?

Hello, I can’t make a query to the database in any way, I’ve been sitting for two days and I can’t correctly display the records
from the database. Google could not help :)

There is a table where there is, for example, Username | Amount1 | Amount2 | Amount3
These where amount stores amounts like 105.56 and so on. In general, numbers.

I need to output like this, calculate for each user Amount1 + Amount2 + Amount3 and display the result on the page, for example, the largest tops 20. That is, in descending order of the amount. There can be up to several thousand entries in a table.

What do you recommend?

Thank you so much in advance for taking the time to help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nozzy, 2020-04-28
@Docaram

select username,
sum(Amount1  + Amount2 + Amount3) as total
from my_table
group by username
order by total desc limit 20

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question