我在选择多行后需要面对的问题,遍历每一行并将那些有相关信息的人提取到第一行。
示例:
select NAME,ENGLISH_GRADE,FRANCE_GRAE
from (some complex query that have order by and returns 100 rows) WHOLE_ROWS
where
//Here I need to loop over WHOLE_ROWS and make something like that:
//if(currentRow.ENGLISH_GRADE==WHOLE_ROWS(0).ENGLISH_GRADE)
//fetch this row
答案 0 :(得分:1)
基本上,您需要将查询加入到自身中。您可以使用子查询因子子句:
WITH complex_query AS
( ... complex query here ... )
SELECT
FROM complex_query cq1
WHERE cq1.english_grade = ( SELECT english_grade FROM cq1
WHERE rownum = 1 )
这是SQL Fiddle。你也可以用分析来做到这一点,但在我看来这些更难以理解。