I standard SQL kan dette gøres ved hjælp af en vinduesfunktion
select test_type, model, firmware_version, avg_throughput
from (
select test_type, model, firmware_version, avg_throughput,
min(firmware_version) over (partition by test_type, model) as min_firmware
from temp_table
) t
where firmware_version = min_firmware;
Postgres har dog distinct on
operatør, som normalt er hurtigere end den tilsvarende løsning med en vinduesfunktion:
select distinct on (test_type, model)
test_type, model, firmware_version, avg_throughput
from temp_table
order by test_type, model, firmware_version;
SQLFiddle-eksempel:http://sqlfiddle.com/#!15/563bd/1