oracle语句


 

要求:

1.查询出所有的status 为 null 时aswr_idx的第一条记录。

例如:

aswr_idx为aswf20111123187335这条如果status中有N就不用查。

 

 

 

按ASWR_IDX分组,并查出分组中的第一条记录:
[code="sql"]
select * from
(
select a.*,row_number() over(partition by ASWR_IDX order by rownum) roc
from [要查询的表] a where
not exists (select * from [要查询的表] b where b.status='N' and a.ASWR_IDX =b.ASWR_IDX )
)
where roc = 1
[/code]

图片看不见,大概如下形式:
[code="sql"]select * from (select * from tab where status is null)
where rownum=1[/code]

[code="java"]select * from (select * from tab where status is null order by aswr_idx
)

where rownum=1 [/code]