我错过了一块拼图。我想按strid
选择c_date
订单的第一行,然后按strid
分组。
我的sql是:
--there should be some 'FIRST' function on strid
select strid over(partition by strid order by c_date)
from tab
where c_date > :1
and c_date <= :2
标签
strid VARCHAR2(255 CHAR)
c_date TIMESTAMP(6) WITH TIME ZONE
我可以使用row_number
,然后选择row_number=1
,但我正在尝试避免此子查询,我正在搜索更优化的内容..
答案 0 :(得分:1)
尝试first_value
:
-- do you really want to partition by strid?
select first_value(strid) over (partition by strid order by c_date)
from tab
where (c_date > :1)
and (c_date <= :2)