想要在 Postgresql 中使用 SQL 打印具有较低 运行 订单值的记录

Want to print the records with lower run order value using SQL in Postgresql

下面是 table :

Master_Key  Slave_Key   Scenario_Code   Run_Order
1506        1447           S20             3
1506        2447           S20             1
3506        3445           S11             2
3506        4445           S11             4

我期望的输出:

Master_Key  Slave_Key   Scenario_Code   Run_Order
1506        2447           S20             1
3506        3445           S11             2

所以根据最小 run_order 值,我想要输出

这可以在 Postgres 中使用 distinct on () 来完成:

select distinct on (master_key) *
from the_table
order by master_key, run_order;

Online example