with t as (
select 77 a, 1 row_order from dual union all
select 74 a, 2 row_order from dual union all
select 67 a, 3 row_order from dual union all
select 56 a, 4 row_order from dual union all
select 42 a, 5 row_order from dual union all
select 24 a, 6 row_order from dual union all
select 20 a, 7 row_order from dual union all
select 19 a, 8 row_order from dual union all
select -17 a, 9 row_order from dual union all
select -28 a, 10 row_order from dual union all
select -31 a, 11 row_order from dual union all
select -36 a, 12 row_order from dual
), t1 as (
select a, row_number() over (partition by case when a < 0 then 0 else 1 end order by row_order) rn from t
)
select * from t1 where rn = 1 and a < 0;
3条答案
按热度按时间jchrr9hc1#
如果需要完整的行,可以使用:
如果有另一列指定行的顺序,则:
3zwtqj6y2#
要选择最大负数,可以执行以下操作:
请记住,在关系数据库表中,行没有固有的顺序。因此,在没有排序标准的情况下,不存在“负值开始的第一行”这样的东西。
deikduxw3#
假设您有一个用于排序的列,它定义了行的顺序,它可以如下所示:
它使用一个窗口函数来确定第一行(这里是正数a和负数a),然后它选择遇到的第一行是负数。