oracle查詢:分組查詢,取出每組中的第一條記錄
參考sql reference文件:
Analytic functions compute an aggregate value based on a group of rows. They differ
from aggregate functions in that they return multiple rows for each group.
分析一個聚合函式計算值基於一組行。他們不同於聚合函式返回多個行每組。
Analytic
functions are the last set of operations performed in a query except for the final ORDER
BY
clause.
All joins and all WHERE
, GROUP
BY
,
and HAVING
clauses are completed
before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER
BY
clause.
解析函式的最後一組操作中執行一個查詢,除了最後的ORDER
BY子句。所有連線和地方、GROUP BY和之前有條款完成分析處理功能。因此,解析函式只能出現在選擇列表中或ORDER
BY子句。
語法結構:
analytic_function ([ arguments ]) OVER (analytic_clause)
其中analytic_clause結構包括:
[ query_partition_clause ] [ order_by_clause [ windowing_clause ] ]
也就是:函式名( [ 引數 ] ) over( [ 分割槽子句 ] [ 排序子句 [ 滑動視窗子句 ] ])
這裡PARTITION BY 引導的分割槽子句類似於聚組函式中的group by,排序子句可看成是select語句中的order by.