Oracle分析函数基本概念和语法总结
分析函数基于一个行集计算聚集值,和聚合函数不同的地方在于分析函数会返回多行。除了最后的order by子句,分析函数是一个查询中
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. The group of rows is called a window and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.
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子句,分析函数是一个查询中最后被执行的操作,所有的join,where,group by,having语句都在分析函数之前执行,,因此分析函数只能出现在select语句或者order by子句中。
分析函数语法
analytic_function([arguments])
OVER(
[partition_clause]
[order_by_clause[windowing_clause]]
)
1)分析函数
有以下的分析函数,带*号的函数表示允许windowing子句。
AVG *
CORR *
COUNT *
COVAR_POP *
COVAR_SAMP *
CUME_DIST
DENSE_RANK
FIRST
FIRST_VALUE *
LAG
LAST
LAST_VALUE *
LEAD
LISTAGG
MAX *
MIN *
NTH_VALUE*
NTILE
PERCENT_RANK
PERCENTILE_CONT
PERCENTILE_DISC
RANK
RATIO_TO_REPORT
REGR_ (Linear Regression) Functions *
ROW_NUMBER
STDDEV *
STDDEV_POP *
STDDEV_SAMP *
SUM *
VAR_POP *
VAR_SAMP *
VARIANCE *
2)PARTITION子句
按照表达式分分组,如果省略此子句,则全部的结果集被看作是一个组。
3)ORDER BY子句
ORDER BY将添加一个默认的WINDOWING子句,这个窗口从分组的第一行开始,一直继续到当前行(值),
即RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
没有ORDER BY时,默认的窗口是组中的全部行。
4)WINDOWING子句
定义分析函数作用的行集合,集合中的数据可以看作是一个窗口。
要使用WINDOWING子句,必须使用ORDER BY子句。
有2个建立窗口的关键字:ROWS和RANGE。
ROWS表示一个物理窗口(行);RANGE表示一个逻辑窗口。
BETWEEN...AND: 指定一个范围,如果省略,只指定一个端点,它将作为起点,终点是当前行。
UNBOUNDED PRECEDING:表示窗口从当前分组的第一行开始。
UNBOUNDED FOLLOWING:表示窗口,结束于当前分组的最后一行。
CURRENT ROW:表示窗口开始/结束于当前行或者当前值。
value_expr PRECEDING/value_expr FOLLOWING:指定一个物理或者逻辑的偏移量。
下面通过几个例子来理解这些概念。emp表中有如下数据:
wmsys.wm_concat()函数可以用来进行字段合并,把多行的某一列数据合并成一行显示。
例如,下面利用这个函数把一个部门的所有人名显示在一行。
上面的例子里wm_concat()作为聚合函数使用,下面看看它作为分析函数的结果。
可以看到和聚合函数用法不同的是分析函数为每一行都返回一个结果。
所以在每个部门分组中的所有人名都会显示。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PrimeFactor−Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example−Primefactorsof288are:288=2x2x2x2x2

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.

Reliable digital currency platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini. These exchanges have their own characteristics. Users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

This article provides Android and Apple mobile APP download methods for mainstream digital currency trading platforms such as Binance, OKX, Gate.io, Huobi Global, Coinbase, KuCoin, Kraken and Bitfinex. Whether it is an Android user or an Apple user, you can easily find the official APP download link for the corresponding platform and complete the installation according to the steps. The article provides detailed guidance on searching and downloading on their respective official websites or app stores, and provides instructions on the special steps for installing APK files on Android, so that users can download and use them quickly and easily.

The rankings of the top ten virtual currency trading platforms are: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Gemini. The ranking is based on comprehensive considerations such as platform liquidity, currency selection, security, user experience, handling fees and compliance, but is for reference only. Investment should be cautious and at your own risk.
