I have a table like this:
id | name | salary
------------------
1 | guy1 | 1000
2 | guy2 | 750
3 | guy3 | 400
4 | guy4 | 1000
5 | guy5 | 925
6 | guy6 | 900
I need to take the highest salaries (in this case 2 * 1000) and the lowest (in this case 1 * 400), and return the difference between highest and lowest calculated like this:
1000 * 2 - 400 * 1 = 1600
difference
----------
1600
I tried to filter the table where salaries are highest and lowest but failed.
If the table is empty the result should be 0.