mysql – How do I filter the data in a descending way?


I'm trying to filter the data of a table I have in SQL from the highest value to the lowest, but I'm not succeeding at all with MySQL.

Source code below

select max(id_nf), min(quantidade * valor_unit) AS VALOR_TOTAL from objects, 

Exercise below:

Search the total value of the NF and order the result from the highest value to the lowest. The columns present in the result of the query are: ID_NF , VALOR_TOTAL .

Note: VALOR_TOTAL is obtained by the formula: ∑ QUANTIDADE * VALOR_UNIT .


I think what the exercise asks for is a sum of the total amount that would be:

select id_nf,sum(quantidade * valor_unit) as valor_total 
from objects 
group by id_nf 
order by 2 desc
Scroll to Top