Perform subtraction using aggregation functions

Asked

Viewed 113 times

0

I have a table immovable with the fields of code, price and area. I need to find out what is the price difference between the largest and the smallest property in the table (in a matter of area).

I tried this, but the difference is made between the highest and lowest table price, regardless of the area.

select (max(vl_preco)) - (min(vl_preco)) from imovel;

With the following query I have the return of the prices by order of the area, but I would need to subtract the last value with the first presented.

select max(vl_preco) from imovel group by nr_areatotal;

Is there any way to do this or some more efficient way?

Thank you in advance.

  • You’ve tried to mix the two concepts? select (max(vl_preco)) - (min(vl_preco)) from imovel group by nr_areatotal;

  • Already, but it returns a result for still guy found. And I honestly don’t know what these values are, but none matches the difference in values of the largest property with the smallest.

  • 1

    http://sqlfiddle.com/#! 9/cec83/1 Missing the nr_areatotal in SELECT as well.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.