i have postgresql db with a table t1 and i want to calculate a threshold. the threshold should be for example car 1 uses more fuel than 75 % of all cars, car2 uses more fuel than 50% of all cars, .... mathematically i understand what i want to do, but i dont know how to build the query
id | name | value | threshold
________________________
1 | car1 | 30 | ...%
2 | car2 | 15 | ..%
3 | car3 | 7 |
4 | car4 | 5 |
here is a sql fiddle http://sqlfiddle.com/#!15/1e914/1
UPDATE t1
SET threshold =
select count(value)
from t1
where (value > [over each row]) and followed by *100/the overall count()
sorry for that bad try but i am kind of lost. also tried some aggregate functions.