SQL查询,如果价格高于以前的ID和价格记录,则返回记录



当我有一个类似于以下的数据集时,我在编写SQL查询以返回记录时遇到问题:

id 价格
32967 39
14675 40
26434 41
18495 42
19698 43
19090 44
9278 45
14932 46

如果我理解正确,累积min()可以满足您的要求:

select t.*
from (select t.*,
min(id) over (order by price rows between unbounded preceding and 1 preceding) as prev_min_id
from t
) t
where prev_min_id is null or id < prev_min_id;

这里有一个db<gt;不停摆弄

最新更新