Oracle中的within,Oracle函数 --聚合函数中的语法within group

Oracle的聚合函数一般与group by 联合使用,但一般通过group by 聚合

但某些聚合函数会后跟

WITHIN GROUP

(ORDER BY

expr [ DESC | ASC ]

[ NULLS { FIRST | LAST } ]

[, expr [ DESC | ASC ]

[ NULLS { FIRST | LAST } ]

]...

)

) 指定在group 组内的顺序。

可理解为 在组内的顺序,日后也许会有其他应用。

For example 1 :

同组字符串拼接函数(11gR2新增, 与10g中 WMSYS.WM_CONCAT相同)

LISTAGG(measure_expr [, 'delimiter'])

WITHIN GROUP (order_by_clause) [OVER query_partition_clause]

(注: over()为可选语法,在次函数中,与group by 作用相同,即 group by () 与over()选一即可)

例一:合并同组的字符,连接方式以city倒叙排序

with temp as(

select 'China' nation ,'Guangzhou' city from dual union all

select 'China' nation ,'Shanghai' city from dual union all

select 'China' nation ,'Beijing' city from dual uni

你可能感兴趣的:(Oracle中的within)