<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Analytic functions</title>
    <link>/en/sql-reference/functions/analytic-functions/</link>
    <description>Recent content in Analytic functions on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/sql-reference/functions/analytic-functions/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Sql-Reference: ARGMAX [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/argmax-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/argmax-analytic/</guid>
      <description>
        
        
        &lt;p&gt;This function is patterned after the mathematical function &lt;code&gt;argmax(&lt;/code&gt;&lt;em&gt;&lt;code&gt;f&lt;/code&gt;&lt;/em&gt;&lt;code&gt;(&lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;))&lt;/code&gt;, which returns the value of &lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt; that maximizes &lt;em&gt;&lt;code&gt;f&lt;/code&gt;&lt;/em&gt;&lt;code&gt;(&lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt;. Similarly, ARGMAX takes two arguments &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; and &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt;, where both are columns or column expressions in the queried dataset. ARGMAX finds the row with the largest non-null value in &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; and returns the value of &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt; in that row. If multiple rows contain the largest &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; value, ARGMAX returns &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt; from the first row that it finds.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ARGMAX ( &lt;span class=&#34;code-variable&#34;&gt;target&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;arg&lt;/span&gt; )  OVER ( [ PARTITION BY &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[,...] ] [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt;, &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Columns in the queried dataset.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

ARGMAX does not support &lt;a href=&#34;../../../../en/sql-reference/data-types/spatial-data-types/&#34;&gt;spatial data types&lt;/a&gt;: GEOMETRY and GEOGRAPHY.

&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the following window clauses:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PARTITION BY &lt;/code&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;: Groups (partitions) input rows according to the values in &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;, which resolves to one or more columns in the queried dataset. If you omit this clause, ARGMAX processes all input rows as a single partition.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;: Specifies how to sort input rows. If the OVER clause also includes a partition clause, rows are sorted separately within each partition.&lt;/p&gt;

&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
To ensure consistent results when multiple rows contain the largest &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; value, include a window order clause that sorts on &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt;.
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For details, see &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Create and populate table &lt;code&gt;service_info&lt;/code&gt;, which contains information on various services, their respective development groups, and their userbase. A NULL in the &lt;code&gt;users&lt;/code&gt; column indicates that the service has not been released, and so it cannot have users.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE service_info(dev_group VARCHAR(10), product_name VARCHAR(30), users INT);
=&amp;gt; COPY t FROM stdin NULL AS &amp;#39;null&amp;#39;;
&amp;gt;&amp;gt; iris|chat|48193
&amp;gt;&amp;gt; aspen|trading|3000
&amp;gt;&amp;gt; orchid|cloud|990322
&amp;gt;&amp;gt; iris|video call| 10203
&amp;gt;&amp;gt; daffodil|streaming|44123
&amp;gt;&amp;gt; hydrangea|password manager|null
&amp;gt;&amp;gt; hydrangea|totp|1837363
&amp;gt;&amp;gt; daffodil|clip share|3000
&amp;gt;&amp;gt; hydrangea|e2e sms|null
&amp;gt;&amp;gt; rose|crypto|null
&amp;gt;&amp;gt; iris|forum|48193
&amp;gt;&amp;gt; \.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ARGMAX returns the value in the &lt;code&gt;product_name&lt;/code&gt; column that maximizes the value in the &lt;code&gt;users&lt;/code&gt; column. In this case, ARGMAX returns &lt;code&gt;totp&lt;/code&gt;, which indicates that the &lt;code&gt;totp&lt;/code&gt; service has the largest user base:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT dev_group, product_name, users, ARGMAX(users, product_name) OVER (ORDER BY dev_group ASC) FROM service_info;
 dev_group |   product_name   |  users  | ARGMAX
-----------+------------------+---------+--------
 aspen     | trading          |    3000 | totp
 daffodil  | clip share       |    3000 | totp
 daffodil  | streaming        |   44123 | totp
 hydrangea | e2e sms          |         | totp
 hydrangea | password manager |         | totp
 hydrangea | totp             | 1837363 | totp
 iris      | chat             |   48193 | totp
 iris      | forum            |   48193 | totp
 iris      | video call       |   10203 | totp
 orchid    | cloud            |  990322 | totp
 rose      | crypto           |         | totp
(11 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next query partitions the data on &lt;code&gt;dev_group&lt;/code&gt; to identify the most popular service created by each development group. ARGMAX returns NULL if the partition&#39;s &lt;code&gt;users&lt;/code&gt; column contains only NULL values and breaks ties using the first value in &lt;code&gt;product_name&lt;/code&gt; from the top of the partition.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT dev_group, product_name, users, ARGMAX(users, product_name) OVER (PARTITION BY dev_group ORDER BY product_name ASC) FROM service_info;
 dev_group |   product_name   |  users  |  ARGMAX
-----------+------------------+---------+-----------
 iris      | chat             |   48193 | chat
 iris      | forum            |   48193 | chat
 iris      | video call       |   10203 | chat
 orchid    | cloud            |  990322 | cloud
 aspen     | trading          |    3000 | trading
 daffodil  | clip share       |    3000 | streaming
 daffodil  | streaming        |   44123 | streaming
 rose      | crypto           |         |
 hydrangea | e2e sms          |         | totp
 hydrangea | password manager |         | totp
 hydrangea | totp             | 1837363 | totp
(11 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/argmin-analytic/#&#34;&gt;ARGMIN [analytic]&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: ARGMIN [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/argmin-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/argmin-analytic/</guid>
      <description>
        
        
        &lt;p&gt;This function is patterned after the mathematical function &lt;code&gt;argmin(&lt;/code&gt;&lt;em&gt;&lt;code&gt;f&lt;/code&gt;&lt;/em&gt;&lt;code&gt;(&lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;))&lt;/code&gt;, which returns the value of &lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt; that minimizes &lt;em&gt;&lt;code&gt;f&lt;/code&gt;&lt;/em&gt;&lt;code&gt;(&lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt;. Similarly, ARGMIN takes two arguments &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; and &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt;, where both are columns or column expressions in the queried dataset. ARGMIN finds the row with the smallest non-null value in &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; and returns the value of &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt; in that row. If multiple rows contain the smallest &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; value, ARGMIN returns &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt; from the first row that it finds.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ARGMIN ( &lt;span class=&#34;code-variable&#34;&gt;target&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;arg&lt;/span&gt; )  OVER ( [ PARTITION BY &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[,...] ] [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;arguments&#34;&gt;Arguments&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt;, &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Columns in the queried dataset.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

ARGMIN does not support &lt;a href=&#34;../../../../en/sql-reference/data-types/spatial-data-types/&#34;&gt;spatial data types&lt;/a&gt;: GEOMETRY and GEOGRAPHY.

&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the following window clauses:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PARTITION BY &lt;/code&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;: Groups (partitions) input rows according to the values in &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;, which resolves to one or more columns in the queried dataset. If you omit this clause, ARGMIN processes all input rows as a single partition.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;: Specifies how to sort input rows. If the &lt;code&gt;OVER&lt;/code&gt; clause also includes a partition clause, rows are sorted separately within each partition.&lt;/p&gt;

&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
To ensure consistent results when multiple rows contain the smallest &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; value, include a window order clause that sorts on &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt;.
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For details, see &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Create and populate table &lt;code&gt;service_info&lt;/code&gt;, which contains information on various services, their respective development groups, and their userbase. A NULL in the &lt;code&gt;users&lt;/code&gt; column indicates that the service has not been released, and so it cannot have users.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE service_info(dev_group VARCHAR(10), product_name VARCHAR(30), users INT);
=&amp;gt; COPY t FROM stdin NULL AS &amp;#39;null&amp;#39;;
&amp;gt;&amp;gt; iris|chat|48193
&amp;gt;&amp;gt; aspen|trading|3000
&amp;gt;&amp;gt; orchid|cloud|990322
&amp;gt;&amp;gt; iris|video call| 10203
&amp;gt;&amp;gt; daffodil|streaming|44123
&amp;gt;&amp;gt; hydrangea|password manager|null
&amp;gt;&amp;gt; hydrangea|totp|1837363
&amp;gt;&amp;gt; daffodil|clip share|3000
&amp;gt;&amp;gt; hydrangea|e2e sms|null
&amp;gt;&amp;gt; rose|crypto|null
&amp;gt;&amp;gt; iris|forum|48193
&amp;gt;&amp;gt; \.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ARGMIN returns the value in the &lt;code&gt;product_name&lt;/code&gt; column that minimizes the value in the &lt;code&gt;users&lt;/code&gt; column. In this case, ARGMIN returns &lt;code&gt;totp&lt;/code&gt;, which indicates that the &lt;code&gt;totp&lt;/code&gt; service has the smallest user base:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT dev_group, product_name, users, ARGMIN(users, product_name) OVER (ORDER BY dev_group ASC) FROM service_info;
 dev_group |   product_name   |  users  | ARGMIN
-----------+------------------+---------+---------
 aspen     | trading          |    3000 | trading
 daffodil  | clip share       |    3000 | trading
 daffodil  | streaming        |   44123 | trading
 hydrangea | e2e sms          |         | trading
 hydrangea | password manager |         | trading
 hydrangea | totp             | 1837363 | trading
 iris      | chat             |   48193 | trading
 iris      | forum            |   48193 | trading
 iris      | video call       |   10203 | trading
 orchid    | cloud            |  990322 | trading
 rose      | crypto           |         | trading
(11 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next query partitions the data on &lt;code&gt;dev_group&lt;/code&gt; to identify the least popular service created by each development group. ARGMIN returns NULL if the partition&#39;s &lt;code&gt;users&lt;/code&gt; column contains only NULL values and breaks ties using the first value in &lt;code&gt;product_name&lt;/code&gt; from the top of the partition.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT dev_group, product_name, users, ARGMIN(users, product_name) OVER (PARTITION BY dev_group ORDER BY product_name ASC) FROM service_info;
 dev_group |   product_name   |  users  |   ARGMIN
-----------+------------------+---------+------------
 iris      | chat             |   48193 | video call
 iris      | forum            |   48193 | video call
 iris      | video call       |   10203 | video call
 orchid    | cloud            |  990322 | cloud
 aspen     | trading          |    3000 | trading
 daffodil  | clip share       |    3000 | clip share
 daffodil  | streaming        |   44123 | clip share
 rose      | crypto           |         |
 hydrangea | e2e sms          |         | totp
 hydrangea | password manager |         | totp
 hydrangea | totp             | 1837363 | totp
(11 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/argmax-analytic/#&#34;&gt;ARGMAX [analytic]&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: AVG [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/avg-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/avg-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Computes an average of an expression in a group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. &lt;code&gt;AVG&lt;/code&gt; returns the same data type as the expression&#39;s numeric data type.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;AVG&lt;/code&gt; analytic function differs from the 
&lt;code&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/avg-aggregate/#&#34;&gt;AVG&lt;/a&gt;&lt;/code&gt;&lt;/code&gt; aggregate function, which computes the average of an expression over a group of rows.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;AVG ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression &lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any data that can be implicitly converted to a numeric data type.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;overflow-handling&#34;&gt;Overflow handling&lt;/h2&gt;
&lt;p&gt;By default, OpenText™ Analytics Database allows silent numeric overflow when you call this function on numeric data types. For more information on this behavior and how to change it, see&lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/numeric-data-type-overflow-with-sum-sum-float-and-avg/#&#34;&gt;Numeric data type overflow with SUM, SUM_FLOAT, and AVG&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query finds the sales for that calendar month and returns a running/cumulative average (sometimes called a moving average) using the default window of &lt;code&gt;RANGE UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_month_number_in_year Mo, SUM(product_price) Sales,
   AVG(SUM(product_price)) OVER (ORDER BY calendar_month_number_in_year)::INTEGER Average
   FROM product_dimension pd, date_dimension dm, inventory_fact if
   WHERE dm.date_key = if.date_key AND pd.product_key = if.product_key GROUP BY Mo;
 Mo |  Sales   | Average
----+----------+----------
  1 | 23869547 | 23869547
  2 | 19604661 | 21737104
  3 | 22877913 | 22117374
  4 | 22901263 | 22313346
  5 | 23670676 | 22584812
  6 | 22507600 | 22571943
  7 | 21514089 | 22420821
  8 | 24860684 | 22725804
  9 | 21687795 | 22610470
 10 | 23648921 | 22714315
 11 | 21115910 | 22569005
 12 | 24708317 | 22747281
(12 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To return a moving average that is not a running (cumulative) average, the window can specify &lt;code&gt;ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_month_number_in_year Mo, SUM(product_price) Sales,
   AVG(SUM(product_price)) OVER (ORDER BY calendar_month_number_in_year
     ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING)::INTEGER Average
   FROM product_dimension pd, date_dimension dm, inventory_fact if
   WHERE dm.date_key = if.date_key AND pd.product_key = if.product_key GROUP BY Mo;
 Mo |  Sales   | Average
----+----------+----------
  1 | 23869547 | 22117374
  2 | 19604661 | 22313346
  3 | 22877913 | 22584812
  4 | 22901263 | 22312423
  5 | 23670676 | 22694308
  6 | 22507600 | 23090862
  7 | 21514089 | 22848169
  8 | 24860684 | 22843818
  9 | 21687795 | 22565480
 10 | 23648921 | 23204325
 11 | 21115910 | 22790236
 12 | 24708317 | 23157716
(12 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/count-analytic/#&#34;&gt;COUNT [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/sum-analytic/#&#34;&gt;SUM [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BOOL_AND [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/bool-and-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/bool-and-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the Boolean value of an expression within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. If all input values are true, &lt;code&gt;BOOL_AND&lt;/code&gt; returns &lt;code&gt;t&lt;/code&gt;. Otherwise, it returns &lt;code&gt;f&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;BOOL_AND ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A &lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt; or any non-Boolean data type that can be implicitly converted to a Boolean data type. The function returns a Boolean value.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example illustrates how you can use the &lt;code&gt;BOOL_AND&lt;/code&gt;, &lt;code&gt;BOOL_OR&lt;/code&gt;, and &lt;code&gt;BOOL_XOR&lt;/code&gt; analytic functions. The sample table, employee, includes a column for type of employee and years paid.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE employee(emptype VARCHAR, yearspaid VARCHAR);
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample data into the table to show years paid. In more than one case, an employee could be paid more than once within one year.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO employee
SELECT &amp;#39;contractor1&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor2&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor3&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor1&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor2&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor3&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor4&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor4&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor5&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor5&amp;#39;, &amp;#39;2016&amp;#39;;
 OUTPUT
--------
     10
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query the table. The result shows employees that were paid twice in 2014 (&lt;code&gt;BOOL_AND&lt;/code&gt;), once or twice in 2014 (&lt;code&gt;BOOL_OR&lt;/code&gt;), and specifically not more than once in 2014 (&lt;code&gt;BOOL_XOR&lt;/code&gt;).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT DISTINCT emptype,
BOOL_AND(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidtwicein2014,
BOOL_OR(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidonceortwicein2014,
BOOL_XOR(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidjustoncein2014
FROM employee;


   emptype   | paidtwicein2014 | paidonceortwicein2014 | paidjustoncein2014
-------------+-----------------+-----------------------+--------------------
 contractor1 | t               | t                     | f
 contractor2 | f               | t                     | t
 contractor3 | f               | t                     | t
 contractor4 | t               | t                     | f
 contractor5 | f               | f                     | f
(5 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/bool-and-aggregate/#&#34;&gt;BOOL_AND [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/bool-or-analytic/#&#34;&gt;BOOL_OR [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/bool-xor-analytic/#&#34;&gt;BOOL_XOR [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BOOL_OR [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/bool-or-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/bool-or-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the Boolean value of an expression within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. If at least one input value is true, &lt;code&gt;BOOL_OR&lt;/code&gt; returns &lt;code&gt;t&lt;/code&gt;. Otherwise, it returns &lt;code&gt;f&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;BOOL_OR ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression &lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A &lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt; or any non-Boolean data type that can be implicitly converted to a Boolean data type. The function returns a Boolean value.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example illustrates how you can use the &lt;code&gt;BOOL_AND&lt;/code&gt;, &lt;code&gt;BOOL_OR&lt;/code&gt;, and &lt;code&gt;BOOL_XOR&lt;/code&gt; analytic functions. The sample table, employee, includes a column for type of employee and years paid.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE employee(emptype VARCHAR, yearspaid VARCHAR);
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample data into the table to show years paid. In more than one case, an employee could be paid more than once within one year.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO employee
SELECT &amp;#39;contractor1&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor2&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor3&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor1&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor2&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor3&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor4&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor4&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor5&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor5&amp;#39;, &amp;#39;2016&amp;#39;;
 OUTPUT
--------
     10
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query the table. The result shows employees that were paid twice in 2014 (&lt;code&gt;BOOL_AND&lt;/code&gt;), once or twice in 2014 (&lt;code&gt;BOOL_OR&lt;/code&gt;), and specifically not more than once in 2014 (&lt;code&gt;BOOL_XOR&lt;/code&gt;).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT DISTINCT emptype,
BOOL_AND(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidtwicein2014,
BOOL_OR(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidonceortwicein2014,
BOOL_XOR(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidjustoncein2014
FROM employee;


   emptype   | paidtwicein2014 | paidonceortwicein2014 | paidjustoncein2014
-------------+-----------------+-----------------------+--------------------
 contractor1 | t               | t                     | f
 contractor2 | f               | t                     | t
 contractor3 | f               | t                     | t
 contractor4 | t               | t                     | f
 contractor5 | f               | f                     | f
(5 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/bool-or-aggregate/#&#34;&gt;BOOL_OR [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/bool-and-analytic/#&#34;&gt;BOOL_AND [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/bool-xor-analytic/#&#34;&gt;BOOL_XOR [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BOOL_XOR [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/bool-xor-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/bool-xor-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the Boolean value of an expression within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. If only one input value is true, &lt;code&gt;BOOL_XOR&lt;/code&gt; returns &lt;code&gt;t&lt;/code&gt;. Otherwise, it returns &lt;code&gt;f&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;BOOL_XOR ( &lt;span class=&#34;code-variable&#34;&gt;expression &lt;/span&gt;) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression &lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A &lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt; or any non-Boolean data type that can be implicitly converted to a Boolean data type. The function returns a Boolean value.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example illustrates how you can use the &lt;code&gt;BOOL_AND&lt;/code&gt;, &lt;code&gt;BOOL_OR&lt;/code&gt;, and &lt;code&gt;BOOL_XOR&lt;/code&gt; analytic functions. The sample table, employee, includes a column for type of employee and years paid.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE employee(emptype VARCHAR, yearspaid VARCHAR);
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample data into the table to show years paid. In more than one case, an employee could be paid more than once within one year.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO employee
SELECT &amp;#39;contractor1&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor2&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor3&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor1&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor2&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor3&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor4&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor4&amp;#39;, &amp;#39;2014&amp;#39;
UNION ALL
SELECT &amp;#39;contractor5&amp;#39;, &amp;#39;2015&amp;#39;
UNION ALL
SELECT &amp;#39;contractor5&amp;#39;, &amp;#39;2016&amp;#39;;
 OUTPUT
--------
     10
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query the table. The result shows employees that were paid twice in 2014 (&lt;code&gt;BOOL_AND&lt;/code&gt;), once or twice in 2014 (&lt;code&gt;BOOL_OR&lt;/code&gt;), and specifically not more than once in 2014 (&lt;code&gt;BOOL_XOR&lt;/code&gt;).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT DISTINCT emptype,
BOOL_AND(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidtwicein2014,
BOOL_OR(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidonceortwicein2014,
BOOL_XOR(yearspaid=&amp;#39;2014&amp;#39;) OVER (PARTITION BY emptype) AS paidjustoncein2014
FROM employee;


   emptype   | paidtwicein2014 | paidonceortwicein2014 | paidjustoncein2014
-------------+-----------------+-----------------------+--------------------
 contractor1 | t               | t                     | f
 contractor2 | f               | t                     | t
 contractor3 | f               | t                     | t
 contractor4 | t               | t                     | f
 contractor5 | f               | f                     | f
(5 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/bool-xor-aggregate/#&#34;&gt;BOOL_XOR [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/bool-and-analytic/#&#34;&gt;BOOL_AND [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/bool-or-analytic/#&#34;&gt;BOOL_OR [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: CONDITIONAL_CHANGE_EVENT [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/conditional-change-event-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/conditional-change-event-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Assigns an event window number to each row, starting from 0, and increments by 1 when the result of evaluating the argument expression on the current row differs from that on the previous row.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CONDITIONAL_CHANGE_EVENT ( &lt;span class=&#34;code-variable&#34;&gt;expression &lt;/span&gt;) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;SQL scalar expression that is evaluated on an input record. The result of *&lt;code&gt;expression &lt;/code&gt;*can be of any data type.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;notes&#34;&gt;Notes&lt;/h2&gt;
&lt;p&gt;The analytic &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt; is required but the &lt;em&gt;&lt;code&gt;window-partition-clause&lt;/code&gt;&lt;/em&gt; is optional.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT CONDITIONAL_CHANGE_EVENT(bid)
          OVER (PARTITION BY symbol ORDER BY ts) AS cce
   FROM TickStore;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The system returns an error when no &lt;code&gt;ORDER BY&lt;/code&gt; clause is present:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT CONDITIONAL_CHANGE_EVENT(bid)
          OVER (PARTITION BY symbol) AS cce
   FROM TickStore;

ERROR:  conditional_change_event must contain an
ORDER BY clause within its analytic clause
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For more examples, see &lt;a href=&#34;../../../../en/data-analysis/sql-analytics/event-based-windows/#&#34;&gt;Event-based windows&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/conditional-true-event-analytic/#&#34;&gt;CONDITIONAL_TRUE_EVENT [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/row-number-analytic/#&#34;&gt;ROW_NUMBER [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/#&#34;&gt;Time series analytics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/event-based-windows/#&#34;&gt;Event-based windows&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: CONDITIONAL_TRUE_EVENT [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/conditional-true-event-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/conditional-true-event-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Assigns an event window number to each row, starting from 0, and increments the number by 1 when the result of the boolean argument expression evaluates true. For example, given a sequence of values for column a, as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;( 1, 2, 3, 4, 5, 6 )
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;CONDITIONAL_TRUE_EVENT(a &amp;gt; 3)&lt;/code&gt; returns &lt;code&gt;0, 0, 0, 1, 2, 3&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CONDITIONAL_TRUE_EVENT ( &lt;span class=&#34;code-variable&#34;&gt;boolean-expression &lt;/span&gt;) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;boolean-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;SQL scalar expression that is evaluated on an input record, type BOOLEAN.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/#&#34;&gt;Analytic functions&lt;/a&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;notes&#34;&gt;Notes&lt;/h2&gt;
&lt;p&gt;The analytic &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt; is required but the &lt;em&gt;&lt;code&gt;window-partition-clause&lt;/code&gt;&lt;/em&gt; is optional.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;gt; SELECT CONDITIONAL_TRUE_EVENT(bid &amp;gt; 10.6)
     OVER(PARTITION BY bid ORDER BY ts) AS cte
   FROM Tickstore;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The system returns an error if the &lt;code&gt;ORDER BY&lt;/code&gt; clause is omitted:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;gt; SELECT CONDITIONAL_TRUE_EVENT(bid &amp;gt; 10.6)
      OVER(PARTITION BY bid) AS cte
   FROM Tickstore;

ERROR:  conditional_true_event must contain an ORDER BY
clause within its analytic clause
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For more examples, see &lt;a href=&#34;../../../../en/data-analysis/sql-analytics/event-based-windows/#&#34;&gt;Event-based windows&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/conditional-change-event-analytic/#&#34;&gt;CONDITIONAL_CHANGE_EVENT [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/#&#34;&gt;Time series analytics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/event-based-windows/#&#34;&gt;Event-based windows&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: COUNT [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/count-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/count-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Counts occurrences within a group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. If you specify * or some non-null constant, &lt;code&gt;COUNT()&lt;/code&gt; counts all rows.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;COUNT ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Returns the number of rows in each group for which the &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; is not null. Can be any expression resulting in BIGINT.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Using the schema defined in &lt;a href=&#34;../../../../en/data-analysis/sql-analytics/window-framing/#&#34;&gt;Window framing&lt;/a&gt;, the following &lt;code&gt;COUNT&lt;/code&gt; function omits window order and window frame clauses; otherwise OpenText™ Analytics Database would treat it as a window aggregate. Think of the window of reporting aggregates as &lt;code&gt;RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT deptno, sal, empno, COUNT(sal)
     OVER (PARTITION BY deptno) AS count FROM emp;

 deptno | sal | empno | count
--------+-----+-------+-------
     10 | 101 |     1 |     2
     10 | 104 |     4 |     2
     20 | 110 |    10 |     6
     20 | 110 |     9 |     6
     20 | 109 |     7 |     6
     20 | 109 |     6 |     6
     20 | 109 |     8 |     6
     20 | 109 |    11 |     6
     30 | 105 |     5 |     3
     30 | 103 |     3 |     3
     30 | 102 |     2 |     3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using &lt;code&gt;ORDER BY sal&lt;/code&gt; creates a moving window query with default window: &lt;code&gt;RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT deptno, sal, empno, COUNT(sal)
     OVER (PARTITION BY deptno ORDER BY sal) AS count
   FROM emp;

 deptno | sal | empno | count
--------+-----+-------+-------
     10 | 101 |     1 |     1
     10 | 104 |     4 |     2
     20 | 100 |    11 |     1
     20 | 109 |     7 |     4
     20 | 109 |     6 |     4
     20 | 109 |     8 |     4
     20 | 110 |    10 |     6
     20 | 110 |     9 |     6
     30 | 102 |     2 |     1
     30 | 103 |     3 |     2
     30 | 105 |     5 |     3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the VMart schema, the following query finds the number of employees who make less than or equivalent to the hourly rate of the current employee. The query returns a running/cumulative average (sometimes called a moving average) using the default window of &lt;code&gt;RANGE UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name AS &amp;#34;last_name&amp;#34;, hourly_rate, COUNT(*)
   OVER (ORDER BY hourly_rate) AS moving_count from employee_dimension;

 last_name  | hourly_rate | moving_count
------------+-------------+--------------
 Gauthier   |           6 |            4
 Taylor     |           6 |            4
 Jefferson  |           6 |            4
 Nielson    |           6 |            4
 McNulty    |        6.01 |           11
 Robinson   |        6.01 |           11
 Dobisz     |        6.01 |           11
 Williams   |        6.01 |           11
 Kramer     |        6.01 |           11
 Miller     |        6.01 |           11
 Wilson     |        6.01 |           11
 Vogel      |        6.02 |           14
 Moore      |        6.02 |           14
 Vogel      |        6.02 |           14
 Carcetti   |        6.03 |           19
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To return a moving average that is not also a running (cumulative) average, the window should specify &lt;code&gt;ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name AS &amp;#34;last_name&amp;#34;, hourly_rate, COUNT(*)
      OVER (ORDER BY hourly_rate ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
   AS moving_count from employee_dimension;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/count-aggregate/#&#34;&gt;COUNT [aggregate]&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/avg-analytic/#&#34;&gt;AVG [analytic]&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/sum-analytic/#&#34;&gt;SUM [analytic]&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: CUME_DIST [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/cume-dist-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/cume-dist-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Calculates the cumulative distribution, or relative rank, of the current row with regard to other rows in the same partition within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;CUME_DIST()&lt;/code&gt; returns a number greater then 0 and less then or equal to 1, where the number represents the relative position of the specified row within a group of &lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt; rows. For a row &lt;code&gt;x&lt;/code&gt; (assuming &lt;code&gt;ASC&lt;/code&gt; ordering), the &lt;code&gt;CUME_DIST&lt;/code&gt; of &lt;code&gt;x&lt;/code&gt; is the number of rows with values lower than or equal to the value of &lt;code&gt;x&lt;/code&gt;, divided by the number of rows in the partition. For example, in a group of three rows, the cumulative distribution values returned would be 1/3, 2/3, and 3/3.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Because the result for a given row depends on the number of rows preceding that row in the same partition, you should always specify a &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt; when you call this function.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CUME_DIST ( ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;  )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the cumulative distribution of sales for different transaction types within each month of the first quarter.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_month_name AS month, tender_type, SUM(sales_quantity),
       CUME_DIST()
   OVER (PARTITION BY calendar_month_name ORDER BY SUM(sales_quantity)) AS
CUME_DIST
   FROM store.store_sales_fact JOIN date_dimension
   USING(date_key) WHERE calendar_month_name IN (&amp;#39;January&amp;#39;,&amp;#39;February&amp;#39;,&amp;#39;March&amp;#39;)
   AND tender_type NOT LIKE &amp;#39;Other&amp;#39;
   GROUP BY calendar_month_name, tender_type;


  month   | tender_type |  SUM   | CUME_DIST
----------+-------------+--------+-----------
 March    | Credit      | 469858 |      0.25
 March    | Cash        | 470449 |       0.5
 March    | Check       | 473033 |      0.75
 March    | Debit       | 475103 |         1
 January  | Cash        | 441730 |      0.25
 January  | Debit       | 443922 |       0.5
 January  | Check       | 446297 |      0.75
 January  | Credit      | 450994 |         1
 February | Check       | 425665 |      0.25
 February | Debit       | 426726 |       0.5
 February | Credit      | 430010 |      0.75
 February | Cash        | 430767 |         1
(12 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percent-rank-analytic/#&#34;&gt;PERCENT_RANK [analytic]&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-disc-analytic/#&#34;&gt;PERCENTILE_DISC [analytic]&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: DENSE_RANK [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/dense-rank-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/dense-rank-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Within each window partition, ranks all rows in the query results set according to the order specified by the window&#39;s &lt;code&gt;ORDER BY&lt;/code&gt; clause. A &lt;code&gt;DENSE_RANK&lt;/code&gt; function returns a sequence of ranking numbers without any gaps.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;DENSE_RANK&lt;/code&gt; executes as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Sorts partition rows as specified by the &lt;code&gt;ORDER BY&lt;/code&gt; clause.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Compares the &lt;code&gt;ORDER BY&lt;/code&gt; values of the preceding row and current row and ranks the current row as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If &lt;code&gt;ORDER BY&lt;/code&gt; values are the same, the current row gets the same ranking as the preceding row.&lt;/p&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Null values are considered equal. For detailed information on how null values are sorted, see &lt;a href=&#34;../../../../en/data-analysis/query-optimization/analytic-functions/null-sort-order/#&#34;&gt;NULL sort order&lt;/a&gt;.

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the &lt;code&gt;ORDER BY&lt;/code&gt; values are different, &lt;code&gt;DENSE_RANK&lt;/code&gt; increments or decrements the current row&#39;s ranking by 1, depending whether sort order is ascending or descending.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;DENSE_RANK&lt;/code&gt; always changes the ranking by 1, so no gaps appear in the ranking sequence. The largest rank value is the number of unique &lt;code&gt;ORDER BY&lt;/code&gt; values returned by the query.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;DENSE_RANK() OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;  )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;compared-with-rank&#34;&gt;Compared with RANK&lt;/h2&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/rank-analytic/#&#34;&gt;RANK&lt;/a&gt;&lt;/code&gt; leaves gaps in the ranking sequence, while &lt;code&gt;DENSE_RANK&lt;/code&gt; does not. The example below compares the behavior of the two functions.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query invokes &lt;code&gt;RANK&lt;/code&gt; and &lt;code&gt;DENSE_RANK&lt;/code&gt; to rank customers by annual income. The two functions return different rankings, as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If &lt;code&gt;annual_salary&lt;/code&gt; contains duplicate values, &lt;code&gt;RANK()&lt;/code&gt; inserts duplicate rankings and then skips one or more values—for example, from 4 to 6 and 7 to 9.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the parallel column &lt;code&gt;Dense Rank&lt;/code&gt;, &lt;code&gt;DENSE_RANK()&lt;/code&gt; also inserts duplicate rankings, but leaves no gaps in the rankings sequence:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt;  SELECT employee_region region, employee_key, annual_salary,
     RANK() OVER (PARTITION BY employee_region ORDER BY annual_salary) Rank,
     DENSE_RANK() OVER (PARTITION BY employee_region ORDER BY annual_salary) &amp;#34;Dense Rank&amp;#34;
     FROM employee_dimension;
              region              | employee_key | annual_salary | Rank | Dense Rank
----------------------------------+--------------+---------------+------+------------
 West                             |         5248 |          1200 |    1 |          1
 West                             |         6880 |          1204 |    2 |          2
 West                             |         5700 |          1214 |    3 |          3
 West                             |         9857 |          1218 |    4 |          4
 West                             |         6014 |          1218 |    4 |          4
 West                             |         9221 |          1220 |    6 |          5
 West                             |         7646 |          1222 |    7 |          6
 West                             |         6621 |          1222 |    7 |          6
 West                             |         6488 |          1224 |    9 |          7
 West                             |         7659 |          1226 |   10 |          8
 West                             |         7432 |          1226 |   10 |          8
 West                             |         9905 |          1226 |   10 |          8
 West                             |         9021 |          1228 |   13 |          9
 ...
 West                             |           56 |        963104 | 2794 |       2152
 West                             |          100 |        992363 | 2795 |       2153
 East                             |         8353 |          1200 |    1 |          1
 East                             |         9743 |          1202 |    2 |          2
 East                             |         9975 |          1202 |    2 |          2
 East                             |         9205 |          1204 |    4 |          3
 East                             |         8894 |          1206 |    5 |          4
 East                             |         7740 |          1206 |    5 |          4
 East                             |         7324 |          1208 |    7 |          5
 East                             |         6505 |          1208 |    7 |          5
 East                             |         5404 |          1208 |    7 |          5
 East                             |         5010 |          1208 |    7 |          5
 East                             |         9114 |          1212 |   11 |          6
 ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: EXPONENTIAL_MOVING_AVERAGE [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/exponential-moving-average-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/exponential-moving-average-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Calculates the exponential moving average (EMA) of expression &lt;em&gt;&lt;code&gt;E&lt;/code&gt;&lt;/em&gt; with smoothing factor &lt;em&gt;&lt;code&gt;X&lt;/code&gt;&lt;/em&gt;. An EMA differs from a simple moving average in that it provides a more stable picture of changes to data over time.&lt;/p&gt;
&lt;p&gt;The EMA is calculated by adding the previous EMA value to the current data point scaled by the smoothing factor, as in the following formula:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;EMA&lt;/code&gt;&lt;/em&gt;&lt;code&gt;=&lt;/code&gt;&lt;em&gt;&lt;code&gt;EMA0&lt;/code&gt;&lt;/em&gt;&lt;code&gt; + (&lt;/code&gt;&lt;em&gt;&lt;code&gt;X&lt;/code&gt;&lt;/em&gt;&lt;code&gt; * (&lt;/code&gt;&lt;em&gt;&lt;code&gt;E&lt;/code&gt;&lt;/em&gt;&lt;code&gt;-&lt;/code&gt;&lt;em&gt;&lt;code&gt;EMA0&lt;/code&gt;&lt;/em&gt;&lt;code&gt;))&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;E&lt;/code&gt;&lt;/em&gt; is the current data point&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;EMA0&lt;/code&gt;&lt;/em&gt; is the previous row&#39;s EMA value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;X&lt;/code&gt;&lt;/em&gt; is the smoothing factor.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This function also works at the row level. For example, EMA assumes the data in a given column is sampled at uniform intervals. If the users&#39; data points are sampled at non-uniform intervals, they should run the time series &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/&#34;&gt;gap filling and interpolation (GFI) &lt;/a&gt;operations before EMA()&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;EXPONENTIAL_MOVING_AVERAGE ( &lt;span class=&#34;code-variable&#34;&gt;E&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;X&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;  )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;E&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The value whose average is calculated over a set of rows. Can be &lt;code&gt;INTEGER&lt;/code&gt;, &lt;code&gt;FLOAT&lt;/code&gt; or &lt;code&gt;NUMERIC&lt;/code&gt; type and must be a constant.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;X&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A positive &lt;code&gt;FLOAT&lt;/code&gt; value between 0 and 1 that is used as the smoothing factor.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example uses time series &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/&#34;&gt;gap filling and interpolation&lt;/a&gt; (GFI) first in a subquery, and then performs an &lt;code&gt;EXPONENTIAL_MOVING_AVERAGE&lt;/code&gt; operation on the subquery result.&lt;/p&gt;
&lt;p&gt;Create a simple four-column table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE ticker(
     time TIMESTAMP,
     symbol VARCHAR(8),
     bid1 FLOAT,
     bid2 FLOAT );
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert some data, including nulls, so GFI can do its interpolation and gap filling:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:00&amp;#39;, &amp;#39;ABC&amp;#39;, 60.45, 60.44);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:01&amp;#39;, &amp;#39;ABC&amp;#39;, 60.49, 65.12);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:02&amp;#39;, &amp;#39;ABC&amp;#39;, 57.78, 59.25);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:03&amp;#39;, &amp;#39;ABC&amp;#39;, null, 65.12);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:04&amp;#39;, &amp;#39;ABC&amp;#39;, 67.88, null);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:00&amp;#39;, &amp;#39;XYZ&amp;#39;, 47.55, 40.15);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:01&amp;#39;, &amp;#39;XYZ&amp;#39;, 44.35, 46.78);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:02&amp;#39;, &amp;#39;XYZ&amp;#39;, 71.56, 75.78);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:03&amp;#39;, &amp;#39;XYZ&amp;#39;, 85.55, 70.21);
=&amp;gt; INSERT INTO ticker VALUES (&amp;#39;2009-07-12 03:00:04&amp;#39;, &amp;#39;XYZ&amp;#39;, 45.55, 58.65);
=&amp;gt; COMMIT;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

During gap filling and interpolation, OpenText™ Analytics Database takes the closest non null value on either side of the time slice and uses that value. For example, if you use a linear interpolation scheme and you do not specify &lt;code&gt;IGNORE NULLS&lt;/code&gt;, and your data has one real value and one null, the result is null. If the value on either side is null, the result is null. See &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/null-values-time-series-data/&#34;&gt;When Time Series Data Contains Nulls&lt;/a&gt; for details.

&lt;/div&gt;
&lt;p&gt;Query the table that you just created to you can see the output:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM ticker;
        time         | symbol | bid1  | bid2
---------------------+--------+-------+-------
 2009-07-12 03:00:00 | ABC    | 60.45 | 60.44
 2009-07-12 03:00:01 | ABC    | 60.49 | 65.12
 2009-07-12 03:00:02 | ABC    | 57.78 | 59.25
 2009-07-12 03:00:03 | ABC    |       | 65.12
 2009-07-12 03:00:04 | ABC    | 67.88 |
 2009-07-12 03:00:00 | XYZ    | 47.55 | 40.15
 2009-07-12 03:00:01 | XYZ    | 44.35 | 46.78
 2009-07-12 03:00:02 | XYZ    | 71.56 | 75.78
 2009-07-12 03:00:03 | XYZ    | 85.55 | 70.21
 2009-07-12 03:00:04 | XYZ    | 45.55 | 58.65
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query processes the first and last values that belong to each 2-second time slice in table &lt;code&gt;trades&lt;/code&gt;&#39; column &lt;code&gt;a&lt;/code&gt;. The query then calculates the exponential moving average of expression fv and lv with a smoothing factor of 50%:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT symbol, slice_time, fv, lv,
     EXPONENTIAL_MOVING_AVERAGE(fv, 0.5)
       OVER (PARTITION BY symbol ORDER BY slice_time) AS ema_first,
   EXPONENTIAL_MOVING_AVERAGE(lv, 0.5)
       OVER (PARTITION BY symbol ORDER BY slice_time) AS ema_last
   FROM (
     SELECT symbol, slice_time,
        TS_FIRST_VALUE(bid1 IGNORE NULLS) as fv,
        TS_LAST_VALUE(bid2 IGNORE NULLS) AS lv
      FROM ticker TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39;
      OVER (PARTITION BY symbol ORDER BY time) ) AS sq;


 symbol |     slice_time      |  fv   |  lv   | ema_first | ema_last
--------+---------------------+-------+-------+-----------+----------
 ABC    | 2009-07-12 03:00:00 | 60.45 | 65.12 |     60.45 |    65.12
 ABC    | 2009-07-12 03:00:02 | 57.78 | 65.12 |    59.115 |    65.12
 ABC    | 2009-07-12 03:00:04 | 67.88 | 65.12 |   63.4975 |    65.12
 XYZ    | 2009-07-12 03:00:00 | 47.55 | 46.78 |     47.55 |    46.78
 XYZ    | 2009-07-12 03:00:02 | 71.56 | 70.21 |    59.555 |   58.495
 XYZ    | 2009-07-12 03:00:04 | 45.55 | 58.65 |   52.5525 |  58.5725
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/timeseries-clause/#&#34;&gt;TIMESERIES clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/#&#34;&gt;Time series analytics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: FIRST_VALUE [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/first-value-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/first-value-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Lets you select the first value of a table or partition (determined by the &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt;) without having to use a self join. This function is useful when you want to use the first value as a baseline in calculations.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;FIRST_VALUE()&lt;/code&gt; with the &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt; to produce deterministic results. If no &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt; is specified for the current row, the default window is &lt;code&gt;UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;FIRST_VALUE ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ IGNORE NULLS ] ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Expression to evaluate—or example, a constant, column, nonanalytic function, function expression, or expressions involving any of these.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;IGNORE NULLS&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies to return the first non-null value in the set, or &lt;code&gt;NULL&lt;/code&gt; if all values are &lt;code&gt;NULL&lt;/code&gt;. If you omit this option and the first value in the set is null, the function returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query asks for the first value in the partitioned day of week, and illustrates the potential nondeterministic nature of &lt;code&gt;FIRST_VALUE()&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_year, date_key, day_of_week, full_date_description,
   FIRST_VALUE(full_date_description)
     OVER(PARTITION BY calendar_month_number_in_year ORDER BY day_of_week)
     AS &amp;#34;first_value&amp;#34;
   FROM date_dimension
   WHERE calendar_year=2003 AND calendar_month_number_in_year=1;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The first value returned is January 31, 2003; however, the next time the same query is run, the first value might be January 24 or January 3, or the 10th or 17th. This is because the analytic &lt;code&gt;ORDER BY&lt;/code&gt; column &lt;code&gt;day_of_week&lt;/code&gt; returns rows that contain ties (multiple Fridays). These repeated values make the &lt;code&gt;ORDER BY&lt;/code&gt; evaluation result nondeterministic, because rows that contain ties can be ordered in any way, and any one of those rows qualifies as being the first value of &lt;code&gt;day_of_week&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt; calendar_year | date_key | day_of_week | full_date_description |    first_value
 --------------+----------+-------------+-----------------------+------------------
          2003 |       31 | Friday      | January 31, 2003      | January 31, 2003
          2003 |       24 | Friday      | January 24, 2003      | January 31, 2003
          2003 |        3 | Friday      | January 3, 2003       | January 31, 2003
          2003 |       10 | Friday      | January 10, 2003      | January 31, 2003
          2003 |       17 | Friday      | January 17, 2003      | January 31, 2003
          2003 |        6 | Monday      | January 6, 2003       | January 31, 2003
          2003 |       27 | Monday      | January 27, 2003      | January 31, 2003
          2003 |       13 | Monday      | January 13, 2003      | January 31, 2003
          2003 |       20 | Monday      | January 20, 2003      | January 31, 2003
          2003 |       11 | Saturday    | January 11, 2003      | January 31, 2003
          2003 |       18 | Saturday    | January 18, 2003      | January 31, 2003
          2003 |       25 | Saturday    | January 25, 2003      | January 31, 2003
          2003 |        4 | Saturday    | January 4, 2003       | January 31, 2003
          2003 |       12 | Sunday      | January 12, 2003      | January 31, 2003
          2003 |       26 | Sunday      | January 26, 2003      | January 31, 2003
          2003 |        5 | Sunday      | January 5, 2003       | January 31, 2003
          2003 |       19 | Sunday      | January 19, 2003      | January 31, 2003
          2003 |       23 | Thursday    | January 23, 2003      | January 31, 2003
          2003 |        2 | Thursday    | January 2, 2003       | January 31, 2003
          2003 |        9 | Thursday    | January 9, 2003       | January 31, 2003
          2003 |       16 | Thursday    | January 16, 2003      | January 31, 2003
          2003 |       30 | Thursday    | January 30, 2003      | January 31, 2003
          2003 |       21 | Tuesday     | January 21, 2003      | January 31, 2003
          2003 |       14 | Tuesday     | January 14, 2003      | January 31, 2003
          2003 |        7 | Tuesday     | January 7, 2003       | January 31, 2003
          2003 |       28 | Tuesday     | January 28, 2003      | January 31, 2003
          2003 |       22 | Wednesday   | January 22, 2003      | January 31, 2003
          2003 |       29 | Wednesday   | January 29, 2003      | January 31, 2003
          2003 |       15 | Wednesday   | January 15, 2003      | January 31, 2003
          2003 |        1 | Wednesday   | January 1, 2003       | January 31, 2003
          2003 |        8 | Wednesday   | January 8, 2003       | January 31, 2003
(31 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The &lt;code&gt;day_of_week&lt;/code&gt; results are returned in alphabetical order because of lexical rules. The fact that each day does not appear ordered by the 7-day week cycle (for example, starting with Sunday followed by Monday, Tuesday, and so on) has no affect on results.

&lt;/div&gt;
&lt;p&gt;To return deterministic results, modify the query so that it performs its analytic &lt;code&gt;ORDER BY&lt;/code&gt; operations on a &lt;strong&gt;unique&lt;/strong&gt; field, such as &lt;code&gt;date_key&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_year, date_key, day_of_week, full_date_description,
   FIRST_VALUE(full_date_description) OVER
     (PARTITION BY calendar_month_number_in_year ORDER BY date_key) AS &amp;#34;first_value&amp;#34;
   FROM date_dimension WHERE calendar_year=2003;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;FIRST_VALUE()&lt;/code&gt; returns a first value of January 1 for the January partition and the first value of February 1 for the February partition. Also, the &lt;code&gt;full_date_description&lt;/code&gt; column contains no ties:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt; calendar_year | date_key | day_of_week | full_date_description | first_value
---------------+----------+-------------+-----------------------+------------
          2003 |        1 | Wednesday   | January 1, 2003       | January 1, 2003
          2003 |        2 | Thursday    | January 2, 2003       | January 1, 2003
          2003 |        3 | Friday      | January 3, 2003       | January 1, 2003
          2003 |        4 | Saturday    | January 4, 2003       | January 1, 2003
          2003 |        5 | Sunday      | January 5, 2003       | January 1, 2003
          2003 |        6 | Monday      | January 6, 2003       | January 1, 2003
          2003 |        7 | Tuesday     | January 7, 2003       | January 1, 2003
          2003 |        8 | Wednesday   | January 8, 2003       | January 1, 2003
          2003 |        9 | Thursday    | January 9, 2003       | January 1, 2003
          2003 |       10 | Friday      | January 10, 2003      | January 1, 2003
          2003 |       11 | Saturday    | January 11, 2003      | January 1, 2003
          2003 |       12 | Sunday      | January 12, 2003      | January 1, 2003
          2003 |       13 | Monday      | January 13, 2003      | January 1, 2003
          2003 |       14 | Tuesday     | January 14, 2003      | January 1, 2003
          2003 |       15 | Wednesday   | January 15, 2003      | January 1, 2003
          2003 |       16 | Thursday    | January 16, 2003      | January 1, 2003
          2003 |       17 | Friday      | January 17, 2003      | January 1, 2003
          2003 |       18 | Saturday    | January 18, 2003      | January 1, 2003
          2003 |       19 | Sunday      | January 19, 2003      | January 1, 2003
          2003 |       20 | Monday      | January 20, 2003      | January 1, 2003
          2003 |       21 | Tuesday     | January 21, 2003      | January 1, 2003
          2003 |       22 | Wednesday   | January 22, 2003      | January 1, 2003
          2003 |       23 | Thursday    | January 23, 2003      | January 1, 2003
          2003 |       24 | Friday      | January 24, 2003      | January 1, 2003
          2003 |       25 | Saturday    | January 25, 2003      | January 1, 2003
          2003 |       26 | Sunday      | January 26, 2003      | January 1, 2003
          2003 |       27 | Monday      | January 27, 2003      | January 1, 2003
          2003 |       28 | Tuesday     | January 28, 2003      | January 1, 2003
          2003 |       29 | Wednesday   | January 29, 2003      | January 1, 2003
          2003 |       30 | Thursday    | January 30, 2003      | January 1, 2003
          2003 |       31 | Friday      | January 31, 2003      | January 1, 2003
          2003 |       32 | Saturday    | February 1, 2003      | February 1, 2003
          2003 |       33 | Sunday      | February 2, 2003      | February 1,2003
      ...
(365 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/last-value-analytic/#&#34;&gt;LAST_VALUE [analytic]&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/datetime-functions/time-slice/#&#34;&gt;TIME_SLICE&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: LAG [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/lag-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/lag-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the value of the input expression at the given offset before the current row within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. This function lets you access more than one row in a table at the same time. This is useful for comparing values when the relative positions of rows can be reliably known. It also lets you avoid the more costly self join, which enhances query processing speed.&lt;/p&gt;
&lt;p&gt;For information on getting the rows that follow, see &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/lead-analytic/&#34;&gt;LEAD&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;LAG ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[, &lt;span class=&#34;code-variable&#34;&gt;offset&lt;/span&gt; ] [, &lt;span class=&#34;code-variable&#34;&gt;default&lt;/span&gt; ] ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The expression to evaluate—for example, a constant, column, non-analytic function, function expression, or expressions involving any of these.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;offset&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Indicates how great is the lag. The default value is 1 (the previous row). This parameter must evaluate to a constant positive integer.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;default&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The value returned if &lt;em&gt;&lt;code&gt;offset&lt;/code&gt;&lt;/em&gt; falls outside the bounds of the table or partition. This value must be a constant value or an expression that can be evaluated to a constant; its data type is coercible to that of the first argument.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;This example sums the current balance by date in a table and also sums the previous balance from the last day. Given the inputs that follow, the data satisfies the following conditions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For each &lt;code&gt;some_id&lt;/code&gt;, there is exactly 1 row for each date represented by &lt;code&gt;month_date&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For each &lt;code&gt;some_id&lt;/code&gt;, the set of dates is consecutive; that is, if there is a row for February 24 and a row for February 26, there would also be a row for February 25.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each &lt;code&gt;some_id&lt;/code&gt; has the same set of dates.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE balances (
       month_date DATE,
       current_bal INT,
       some_id INT);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-24&amp;#39;, 10, 1);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-25&amp;#39;, 10, 1);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-26&amp;#39;, 10, 1);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-24&amp;#39;, 20, 2);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-25&amp;#39;, 20, 2);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-26&amp;#39;, 20, 2);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-24&amp;#39;, 30, 3);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-25&amp;#39;, 20, 3);
=&amp;gt; INSERT INTO balances values (&amp;#39;2009-02-26&amp;#39;, 30, 3);
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now run LAG to sum the current balance for each date and sum the previous balance from the last day:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT month_date,
     SUM(current_bal) as current_bal_sum,
     SUM(previous_bal) as previous_bal_sum FROM
       (SELECT month_date, current_bal,
     LAG(current_bal, 1, 0) OVER
       (PARTITION BY some_id ORDER BY month_date)
     AS previous_bal FROM balances) AS subQ
     GROUP BY month_date ORDER BY month_date;
month_date  | current_bal_sum | previous_bal_sum
------------+-----------------+------------------
 2009-02-24 |              60 |                0
 2009-02-25 |              50 |               60
 2009-02-26 |              60 |               50
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the same example data, the following query would not be allowed because LAG is nested inside an aggregate function:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT month_date,
    SUM(current_bal) as current_bal_sum,
   SUM(LAG(current_bal, 1, 0) OVER
      (PARTITION BY some_id ORDER BY month_date)) AS previous_bal_sum
   FROM some_table GROUP BY month_date ORDER BY month_date;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example uses the &lt;a href=&#34;../../../../en/getting-started/introducing-vmart-example-db/&#34;&gt;VMart database&lt;/a&gt;. LAG first returns the annual income from the previous row, and then it calculates the difference between the income in the current row from the income in the previous row:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT occupation, customer_key, customer_name, annual_income,
   LAG(annual_income, 1, 0) OVER (PARTITION BY occupation
   ORDER BY annual_income) AS prev_income, annual_income -
   LAG(annual_income, 1, 0) OVER (PARTITION BY occupation
   ORDER BY annual_income) AS difference
   FROM customer_dimension ORDER BY occupation, customer_key LIMIT 20;
 occupation | customer_key |    customer_name     | annual_income | prev_income | difference
------------+--------------+----------------------+---------------+-------------+------------
 Accountant |           15 | Midori V. Peterson   |        692610 |      692535 |         75
 Accountant |           43 | Midori S. Rodriguez  |        282359 |      280976 |       1383
 Accountant |           93 | Robert P. Campbell   |        471722 |      471355 |        367
 Accountant |          102 | Sam T. McNulty       |        901636 |      901561 |         75
 Accountant |          134 | Martha B. Overstreet |        705146 |      704335 |        811
 Accountant |          165 | James C. Kramer      |        376841 |      376474 |        367
 Accountant |          225 | Ben W. Farmer        |         70574 |       70449 |        125
 Accountant |          270 | Jessica S. Lang      |        684204 |      682274 |       1930
 Accountant |          273 | Mark X. Lampert      |        723294 |      722737 |        557
 Accountant |          295 | Sharon K. Gauthier   |         29033 |       28412 |        621
 Accountant |          338 | Anna S. Jackson      |        816858 |      815557 |       1301
 Accountant |          377 | William I. Jones     |        915149 |      914872 |        277
 Accountant |          438 | Joanna A. McCabe     |        147396 |      144482 |       2914
 Accountant |          452 | Kim P. Brown         |        126023 |      124797 |       1226
 Accountant |          467 | Meghan K. Carcetti   |        810528 |      810284 |        244
 Accountant |          478 | Tanya E. Greenwood   |        639649 |      639029 |        620
 Accountant |          511 | Midori P. Vogel      |        187246 |      185539 |       1707
 Accountant |          525 | Alexander K. Moore   |        677433 |      677050 |        383
 Accountant |          550 | Sam P. Reyes         |        735691 |      735355 |        336
 Accountant |          577 | Robert U. Vu         |        616101 |      615439 |        662
(20 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next example uses &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/lead-analytic/&#34;&gt;LEAD&lt;/a&gt; and LAG to return the third row after the salary in the current row and fifth salary before the salary in the current row:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT hire_date, employee_key, employee_last_name,
   LEAD(hire_date, 1) OVER (ORDER BY hire_date) AS &amp;#34;next_hired&amp;#34; ,
   LAG(hire_date, 1) OVER (ORDER BY hire_date) AS &amp;#34;last_hired&amp;#34;
   FROM employee_dimension ORDER BY hire_date, employee_key;
 hire_date  | employee_key | employee_last_name | next_hired | last_hired
------------+--------------+--------------------+------------+------------
 1956-04-11 |         2694 | Farmer             | 1956-05-12 |
 1956-05-12 |         5486 | Winkler            | 1956-09-18 | 1956-04-11
 1956-09-18 |         5525 | McCabe             | 1957-01-15 | 1956-05-12
 1957-01-15 |          560 | Greenwood          | 1957-02-06 | 1956-09-18
 1957-02-06 |         9781 | Bauer              | 1957-05-25 | 1957-01-15
 1957-05-25 |         9506 | Webber             | 1957-07-04 | 1957-02-06
 1957-07-04 |         6723 | Kramer             | 1957-07-07 | 1957-05-25
 1957-07-07 |         5827 | Garnett            | 1957-11-11 | 1957-07-04
 1957-11-11 |          373 | Reyes              | 1957-11-21 | 1957-07-07
 1957-11-21 |         3874 | Martin             | 1958-02-06 | 1957-11-11
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;[&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/lead-analytic/&#34;&gt;LEAD&lt;/a&gt;](/en/sql-reference/functions/analytic-functions/lead-analytic/)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: LAST_VALUE [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/last-value-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/last-value-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Lets you select the last value of a table or partition (determined by the &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt;) without having to use a self join. &lt;code&gt;LAST_VALUE&lt;/code&gt; takes the last record from the partition after the window order clause. The function then computes the expression against the last record, and returns the results. This function is useful when you want to use the last value as a baseline in calculations.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;LAST_VALUE()&lt;/code&gt; with the &lt;em&gt;&lt;code&gt;window-order-clause&lt;/code&gt;&lt;/em&gt; to produce deterministic results. If no &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt; is specified for the current row, the default window is &lt;code&gt;UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;.

&lt;div class=&#34;alert admonition tip&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Tip&lt;/h4&gt;

Due to default window semantics, &lt;code&gt;LAST_VALUE&lt;/code&gt; does not always return the last value of a partition. If you omit &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; from the analytic clause, &lt;code&gt;LAST_VALUE&lt;/code&gt; operates on this default window. Although results can seem non-intuitive by not returning the bottom of the current partition, it returns the bottom of the window, which continues to change along with the current input row being processed. If you want to return the last value of a partition, use &lt;code&gt;UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING&lt;/code&gt;. See examples below.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;LAST_VALUE ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ IGNORE NULLS ] ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Expression to evaluate—for example, a constant, column, nonanalytic function, function expression, or expressions involving any of these.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;IGNORE NULLS&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies to return the last non-null value in the set, or &lt;code&gt;NULL&lt;/code&gt; if all values are &lt;code&gt;NULL&lt;/code&gt;. If you omit this option and the last value in the set is null, the function returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Using the schema defined in &lt;a href=&#34;../../../../en/data-analysis/sql-analytics/window-framing/#&#34;&gt;Window framing&lt;/a&gt; in Analyzing Data, the following query does not show the highest salary value by department; instead it shows the highest salary value by department by salary.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT deptno, sal, empno, LAST_VALUE(sal)
       OVER (PARTITION BY deptno ORDER BY sal) AS lv
   FROM emp;
 deptno | sal | empno |    lv
--------+-----+-------+--------
     10 | 101 |     1 |     101
     10 | 104 |     4 |     104
     20 | 100 |    11 |     100
     20 | 109 |     7 |     109
     20 | 109 |     6 |     109
     20 | 109 |     8 |     109
     20 | 110 |    10 |     110
     20 | 110 |     9 |     110
     30 | 102 |     2 |     102
     30 | 103 |     3 |     103
     30 | 105 |     5 |     105
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you include the window frame clause &lt;code&gt;ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING&lt;/code&gt;, &lt;code&gt;LAST_VALUE()&lt;/code&gt; returns the highest salary by department, an accurate representation of the information:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT deptno, sal, empno, LAST_VALUE(sal)
       OVER (PARTITION BY deptno ORDER BY sal
            ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS lv
   FROM emp;
 deptno | sal | empno |    lv
--------+-----+-------+--------
     10 | 101 |     1 |     104
     10 | 104 |     4 |     104
     20 | 100 |    11 |     110
     20 | 109 |     7 |     110
     20 | 109 |     6 |     110
     20 | 109 |     8 |     110
     20 | 110 |    10 |     110
     20 | 110 |     9 |     110
     30 | 102 |     2 |     105
     30 | 103 |     3 |     105
     30 | 105 |     5 |     105
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For more examples, see &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/first-value-analytic/&#34;&gt;FIRST_VALUE()&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/first-value-analytic/#&#34;&gt;FIRST_VALUE [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/datetime-functions/time-slice/#&#34;&gt;TIME_SLICE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: LEAD [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/lead-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/lead-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns values from the row after the current row within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;, letting you access more than one row in a table at the same time. This is useful for comparing values when the relative positions of rows can be reliably known. It also lets you avoid the more costly self join, which enhances query processing speed.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;LEAD ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[, &lt;span class=&#34;code-variable&#34;&gt;offset&lt;/span&gt; ] [, &lt;span class=&#34;code-variable&#34;&gt;default&lt;/span&gt; ] ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The expression to evaluate—for example, a constant, column, non-analytic function, function expression, or expressions involving any of these.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;offset&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Is an optional parameter that defaults to 1 (the next row). This parameter must evaluate to a constant positive integer.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;default&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The value returned if &lt;em&gt;&lt;code&gt;offset&lt;/code&gt;&lt;/em&gt; falls outside the bounds of the table or partition. This value must be a constant value or an expression that can be evaluated to a constant; its data type is coercible to that of the first argument.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;LEAD&lt;/code&gt; finds the hire date of the employee hired just after the current row:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT employee_region, hire_date, employee_key, employee_last_name,
   LEAD(hire_date, 1) OVER (PARTITION BY employee_region ORDER BY hire_date) AS &amp;#34;next_hired&amp;#34;
   FROM employee_dimension ORDER BY employee_region, hire_date, employee_key;
  employee_region  | hire_date  | employee_key | employee_last_name | next_hired
-------------------+------------+--------------+--------------------+------------
 East              | 1956-04-08 |         9218 | Harris             | 1957-02-06
 East              | 1957-02-06 |         7799 | Stein              | 1957-05-25
 East              | 1957-05-25 |         3687 | Farmer             | 1957-06-26
 East              | 1957-06-26 |         9474 | Bauer              | 1957-08-18
 East              | 1957-08-18 |          570 | Jefferson          | 1957-08-24
 East              | 1957-08-24 |         4363 | Wilson             | 1958-02-17
 East              | 1958-02-17 |         6457 | McCabe             | 1958-06-26
 East              | 1958-06-26 |         6196 | Li                 | 1958-07-16
 East              | 1958-07-16 |         7749 | Harris             | 1958-09-18
 East              | 1958-09-18 |         9678 | Sanchez            | 1958-11-10
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next example uses &lt;code&gt;LEAD&lt;/code&gt; and &lt;code&gt;LAG&lt;/code&gt; to return the third row after the salary in the current row and fifth salary before the salary in the current row.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT hire_date, employee_key, employee_last_name,
   LEAD(hire_date, 1) OVER (ORDER BY hire_date) AS &amp;#34;next_hired&amp;#34; ,
   LAG(hire_date, 1) OVER (ORDER BY hire_date) AS &amp;#34;last_hired&amp;#34;
   FROM employee_dimension ORDER BY hire_date, employee_key;
 hire_date  | employee_key | employee_last_name | next_hired | last_hired
------------+--------------+--------------------+------------+------------
 1956-04-11 |         2694 | Farmer             | 1956-05-12 |
 1956-05-12 |         5486 | Winkler            | 1956-09-18 | 1956-04-11
 1956-09-18 |         5525 | McCabe             | 1957-01-15 | 1956-05-12
 1957-01-15 |          560 | Greenwood          | 1957-02-06 | 1956-09-18
 1957-02-06 |         9781 | Bauer              | 1957-05-25 | 1957-01-15
 1957-05-25 |         9506 | Webber             | 1957-07-04 | 1957-02-06
 1957-07-04 |         6723 | Kramer             | 1957-07-07 | 1957-05-25
 1957-07-07 |         5827 | Garnett            | 1957-11-11 | 1957-07-04
 1957-11-11 |          373 | Reyes              | 1957-11-21 | 1957-07-07
 1957-11-21 |         3874 | Martin             | 1958-02-06 | 1957-11-11
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example returns employee name and salary, along with the next highest and lowest salaries.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name, annual_salary,
       NVL(LEAD(annual_salary) OVER (ORDER BY annual_salary),
         MIN(annual_salary) OVER()) &amp;#34;Next Highest&amp;#34;,
       NVL(LAG(annual_salary) OVER (ORDER BY annual_salary),
         MAX(annual_salary)  OVER()) &amp;#34;Next Lowest&amp;#34;
   FROM employee_dimension;
 employee_last_name | annual_salary | Next Highest | Next Lowest
--------------------+---------------+--------------+-------------
 Nielson            |          1200 |         1200 |      995533
 Lewis              |          1200 |         1200 |        1200
 Harris             |          1200 |         1202 |        1200
 Robinson           |          1202 |         1202 |        1200
 Garnett            |          1202 |         1202 |        1202
 Weaver             |          1202 |         1202 |        1202
 Nielson            |          1202 |         1202 |        1202
 McNulty            |          1202 |         1204 |        1202
 Farmer             |          1204 |         1204 |        1202
 Martin             |          1204 |         1204 |        1204
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next example returns, for each assistant director in the employees table, the hire date of the director hired just after the director on the current row. For example, Jackson was hired on 2016-12-28, and the next director hired was Bauer:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name, hire_date,
       LEAD(hire_date, 1) OVER (ORDER BY hire_date DESC) as &amp;#34;NextHired&amp;#34;
   FROM employee_dimension WHERE job_title = &amp;#39;Assistant Director&amp;#39;;
 employee_last_name | hire_date  | NextHired
--------------------+------------+------------
 Jackson            | 2016-12-28 | 2016-12-26
 Bauer              | 2016-12-26 | 2016-12-11
 Miller             | 2016-12-11 | 2016-12-07
 Fortin             | 2016-12-07 | 2016-11-27
 Harris             | 2016-11-27 | 2016-11-15
 Goldberg           | 2016-11-15 |
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/lag-analytic/&#34;&gt;LAG&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MAX [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/max-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/max-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the maximum value of an expression within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. The return value has the same type as the expression data type.&lt;/p&gt;
&lt;p&gt;The analytic functions &lt;code&gt;MIN()&lt;/code&gt; and &lt;code&gt;MAX()&lt;/code&gt; can operate with Boolean values. The &lt;code&gt;MAX()&lt;/code&gt; function acts upon a &lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt; or a value that can be implicitly converted to a Boolean value. If at least one input value is true, &lt;code&gt;MAX()&lt;/code&gt; returns &lt;code&gt;t&lt;/code&gt; (true). Otherwise, it returns &lt;code&gt;f&lt;/code&gt; (false). In the same scenario, the &lt;code&gt;MIN()&lt;/code&gt; function returns &lt;code&gt;t&lt;/code&gt; (true) if all input values are true. Otherwise, it returns &lt;code&gt;f&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
MAX ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any expression for which the maximum value is calculated, typically a &lt;a href=&#34;../../../../en/sql-reference/language-elements/expressions/column-references/&#34;&gt;column reference&lt;/a&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query computes the deviation between the employees&#39; annual salary and the maximum annual salary in Massachusetts:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_state, annual_salary,
     MAX(annual_salary)
       OVER(PARTITION BY employee_state ORDER BY employee_key) max,
          annual_salary- MAX(annual_salary)
       OVER(PARTITION BY employee_state ORDER BY employee_key) diff
   FROM employee_dimension
   WHERE employee_state = &amp;#39;MA&amp;#39;;
 employee_state | annual_salary |  max   |  diff
----------------+---------------+--------+---------
 MA             |          1918 | 995533 | -993615
 MA             |          2058 | 995533 | -993475
 MA             |          2586 | 995533 | -992947
 MA             |          2500 | 995533 | -993033
 MA             |          1318 | 995533 | -994215
 MA             |          2072 | 995533 | -993461
 MA             |          2656 | 995533 | -992877
 MA             |          2148 | 995533 | -993385
 MA             |          2366 | 995533 | -993167
 MA             |          2664 | 995533 | -992869
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;p&gt;The following example shows you the difference between the &lt;code&gt;MIN&lt;/code&gt; and &lt;code&gt;MAX&lt;/code&gt; analytic functions when you use them with a Boolean value. The sample creates a table with two columns, adds two rows of data, and shows sample output for &lt;code&gt;MIN&lt;/code&gt; and &lt;code&gt;MAX&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE min_max_functions (emp VARCHAR, torf BOOL);

INSERT INTO min_max_functions VALUES (&amp;#39;emp1&amp;#39;, 1);
INSERT INTO min_max_functions VALUES (&amp;#39;emp1&amp;#39;, 0);

SELECT DISTINCT emp,
min(torf) OVER (PARTITION BY emp) AS worksasbooleanand,
Max(torf) OVER (PARTITION BY emp) AS worksasbooleanor
FROM min_max_functions;

 emp  | worksasbooleanand | worksasbooleanor
------+-------------------+------------------
 emp1 | f                 | t
(1 row)
&lt;/code&gt;&lt;/pre&gt;
&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/max-aggregate/#&#34;&gt;MAX [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/min-analytic/#&#34;&gt;MIN [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MEDIAN [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/median-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/median-analytic/</guid>
      <description>
        
        
        &lt;p&gt;For each row, returns the median value of a value set within each partition. &lt;code&gt;MEDIAN&lt;/code&gt; determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that data type, and returns that data type.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MEDIAN&lt;/code&gt; is an alias of 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-cont-analytic/#&#34;&gt;PERCENTILE_CONT [analytic]&lt;/a&gt;&lt;/code&gt; with an argument of 0.5 (50%).&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;MEDIAN ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER ( [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the middle value or an interpolated value that would be the middle value once the values are sorted. Null values are ignored in the calculation.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;If the &lt;code&gt;OVER&lt;/code&gt; clause specifies &lt;em&gt;&lt;code&gt;window-partition-clause&lt;/code&gt;&lt;/em&gt;, &lt;code&gt;MEDIAN&lt;/code&gt; groups input rows according to one or more columns or expressions. If this clause is omitted, no grouping occurs and &lt;code&gt;MEDIAN&lt;/code&gt; processes all input rows as a single partition.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;../../../../en/data-analysis/sql-analytics/analytic-query-examples/calculating-median-value/#&#34;&gt;Calculating a median value&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-cont-analytic/#&#34;&gt;PERCENTILE_CONT [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MIN [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/min-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/min-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the minimum value of an expression within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. The return value has the same type as the expression data type.&lt;/p&gt;
&lt;p&gt;The analytic functions &lt;code&gt;MIN()&lt;/code&gt; and &lt;code&gt;MAX()&lt;/code&gt; can operate with Boolean values. The &lt;code&gt;MAX()&lt;/code&gt; function acts upon a &lt;a href=&#34;../../../../en/sql-reference/data-types/boolean-data-type/#&#34;&gt;Boolean data type&lt;/a&gt; or a value that can be implicitly converted to a Boolean value. If at least one input value is true, &lt;code&gt;MAX()&lt;/code&gt; returns &lt;code&gt;t&lt;/code&gt; (true). Otherwise, it returns &lt;code&gt;f&lt;/code&gt; (false). In the same scenario, the &lt;code&gt;MIN()&lt;/code&gt; function returns &lt;code&gt;t&lt;/code&gt; (true) if all input values are true. Otherwise, it returns &lt;code&gt;f&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
MIN ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any expression for which the minimum value is calculated, typically a &lt;a href=&#34;../../../../en/sql-reference/language-elements/expressions/column-references/&#34;&gt;column reference&lt;/a&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example shows how you can query to determine the deviation between the employees&#39; annual salary and the minimum annual salary in Massachusetts:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_state, annual_salary,
      MIN(annual_salary)
      OVER(PARTITION BY employee_state ORDER BY employee_key) min,
        annual_salary- MIN(annual_salary)
      OVER(PARTITION BY employee_state ORDER BY employee_key) diff
   FROM employee_dimension
   WHERE employee_state = &amp;#39;MA&amp;#39;;
 employee_state | annual_salary | min  | diff
----------------+---------------+------+------
 MA             |          1918 | 1204 |  714
 MA             |          2058 | 1204 |  854
 MA             |          2586 | 1204 | 1382
 MA             |          2500 | 1204 | 1296
 MA             |          1318 | 1204 |  114
 MA             |          2072 | 1204 |  868
 MA             |          2656 | 1204 | 1452
 MA             |          2148 | 1204 |  944
 MA             |          2366 | 1204 | 1162
 MA             |          2664 | 1204 | 1460
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;p&gt;The following example shows you the difference between the &lt;code&gt;MIN&lt;/code&gt; and &lt;code&gt;MAX&lt;/code&gt; analytic functions when you use them with a Boolean value. The sample creates a table with two columns, adds two rows of data, and shows sample output for &lt;code&gt;MIN&lt;/code&gt; and &lt;code&gt;MAX&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE min_max_functions (emp VARCHAR, torf BOOL);

INSERT INTO min_max_functions VALUES (&amp;#39;emp1&amp;#39;, 1);
INSERT INTO min_max_functions VALUES (&amp;#39;emp1&amp;#39;, 0);

SELECT DISTINCT emp,
min(torf) OVER (PARTITION BY emp) AS worksasbooleanand,
Max(torf) OVER (PARTITION BY emp) AS worksasbooleanor
FROM min_max_functions;

 emp  | worksasbooleanand | worksasbooleanor
------+-------------------+------------------
 emp1 | f                 | t
(1 row)
&lt;/code&gt;&lt;/pre&gt;
&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/min-aggregate/#&#34;&gt;MIN [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/max-analytic/#&#34;&gt;MAX [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: NTH_VALUE [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/nth-value-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/nth-value-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the value evaluated at the row that is the *&lt;code&gt;n&lt;/code&gt;*th row of the window (counting from 1). If the specified row does not exist, NTH_VALUE returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;NTH_VALUE ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt; [ IGNORE NULLS ] ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ])
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Expression to evaluate. The expression can be a constant, column name, nonanalytic function, function expression, or expressions that include any of these.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;row-number&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the row to evaluate, where &lt;em&gt;&lt;code&gt;row-number&lt;/code&gt;&lt;/em&gt; evaluates to an integer ≥ 1.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;IGNORE NULLS&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies to return the first non-&lt;code&gt;NULL&lt;/code&gt; value in the set, or &lt;code&gt;NULL&lt;/code&gt; if all values are &lt;code&gt;NULL&lt;/code&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;In the following example, for each tuple (current row) in table &lt;code&gt;t1&lt;/code&gt;, the window frame clause defines the window as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ORDER BY b ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For each window, &lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt; for *&lt;code&gt;n&lt;/code&gt;*th value is &lt;code&gt;a+1&lt;/code&gt;. &lt;code&gt;a&lt;/code&gt; is the value of column &lt;code&gt;a&lt;/code&gt; in the tuple.&lt;/p&gt;
&lt;p&gt;NTH_VALUE returns the result of the expression &lt;code&gt;b+1&lt;/code&gt;, where &lt;code&gt;b&lt;/code&gt; is the value of column &lt;code&gt;b&lt;/code&gt; in the *&lt;code&gt;n&lt;/code&gt;*th row, which is the &lt;code&gt;a+1&lt;/code&gt; row within the window.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM t1 ORDER BY a;
 a | b
---+----
 1 | 10
 2 | 20
 2 | 21
 3 | 30
 4 | 40
 5 | 50
 6 | 60
(7 rows)

=&amp;gt; SELECT NTH_VALUE(b+1, a+1) OVER
     (ORDER BY b ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) FROM t1;
 ?column?
----------


       22
       31



(7 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: NTILE [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/ntile-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/ntile-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Equally divides an ordered data set (partition) into a &lt;code&gt;{&lt;/code&gt;&lt;em&gt;&lt;code&gt;value&lt;/code&gt;&lt;/em&gt;&lt;code&gt;}&lt;/code&gt; number of subsets within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;, where the subsets are numbered 1 through the value in parameter &lt;em&gt;&lt;code&gt;constant-value&lt;/code&gt;&lt;/em&gt;. For example, if &lt;em&gt;&lt;code&gt;constant-value&lt;/code&gt;&lt;/em&gt;= 4 and the partition contains 20 rows, &lt;code&gt;NTILE&lt;/code&gt; divides the partition rows into four equal subsets of five rows. &lt;code&gt;NTILE&lt;/code&gt; assigns each row to a subset by giving row a number from 1 to 4. The rows in the first subset are assigned 1, the next five are assigned 2, and so on.&lt;/p&gt;
&lt;p&gt;If the number of partition rows is not evenly divisible by the number of subsets, the rows are distributed so no subset is more than one row larger than any other subset, and the lowest subsets have extra rows. For example, if &lt;em&gt;&lt;code&gt;constant-value&lt;/code&gt;&lt;/em&gt;= 4 and the number of rows = 21, the first subset has six rows, the second subset has five rows, and so on.&lt;/p&gt;
&lt;p&gt;If the number of subsets is greater than the number of rows, then a number of subsets equal to the number of rows is filled, and the remaining subsets are empty.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;NTILE ( &lt;span class=&#34;code-variable&#34;&gt;constant-value&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;constant-value&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the number of subsets , where &lt;em&gt;&lt;code&gt;constant-value&lt;/code&gt;&lt;/em&gt; must resolve to a positive constant for each partition.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query assigns each month&#39;s sales total into one of four subsets:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_month_name AS MONTH, SUM(sales_quantity),
      NTILE(4) OVER (ORDER BY SUM(sales_quantity)) AS NTILE
   FROM store.store_sales_fact JOIN date_dimension
   USING(date_key)
   GROUP BY calendar_month_name
   ORDER BY NTILE;
   MONTH   |   SUM   | NTILE
-----------+---------+-------
 November  | 2040726 |     1
 June      | 2088528 |     1
 February  | 2134708 |     1
 April     | 2181767 |     2
 January   | 2229220 |     2
 October   | 2316363 |     2
 September | 2323914 |     3
 March     | 2354409 |     3
 August    | 2387017 |     3
 July      | 2417239 |     4
 May       | 2492182 |     4
 December  | 2531842 |     4
(12 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-cont-analytic/#&#34;&gt;PERCENTILE_CONT [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/mathematical-functions/width-bucket/#&#34;&gt;WIDTH_BUCKET&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: PERCENT_RANK [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/percent-rank-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/percent-rank-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Calculates the relative rank of a row for a given row in a group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt; by dividing that row’s rank less 1 by the number of rows in the partition, also less 1. &lt;code&gt;PERCENT_RANK&lt;/code&gt; always returns values from 0 to 1 inclusive. The first row in any set has a &lt;code&gt;PERCENT_RANK&lt;/code&gt; of 0. The return value is &lt;code&gt;NUMBER&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;( rank - 1 ) / ( [ rows ] - 1 )
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the preceding formula, &lt;code&gt;rank&lt;/code&gt; is the rank position of a row in the group and &lt;code&gt;rows&lt;/code&gt; is the total number of rows in the partition defined by the &lt;code&gt;OVER()&lt;/code&gt; clause.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;PERCENT_RANK ( ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;  )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example finds the percent rank of gross profit for different states within each month of the first quarter:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_month_name AS MONTH, store_state,
      SUM(gross_profit_dollar_amount),
      PERCENT_RANK() OVER (PARTITION BY calendar_month_name
      ORDER BY SUM(gross_profit_dollar_amount)) AS PERCENT_RANK
   FROM store.store_sales_fact JOIN date_dimension
   USING(date_key)
   JOIN store.store_dimension
   USING (store_key)
   WHERE calendar_month_name IN (&amp;#39;January&amp;#39;,&amp;#39;February&amp;#39;,&amp;#39;March&amp;#39;)
   AND store_state IN (&amp;#39;OR&amp;#39;,&amp;#39;IA&amp;#39;,&amp;#39;DC&amp;#39;,&amp;#39;NV&amp;#39;,&amp;#39;WI&amp;#39;)
   GROUP BY calendar_month_name, store_state
   ORDER BY calendar_month_name, PERCENT_RANK;
  MONTH   | store_state |  SUM   | PERCENT_RANK
----------+-------------+--------+--------------
 February | IA          | 418490 |            0
 February | OR          | 460588 |         0.25
 February | DC          | 616553 |          0.5
 February | WI          | 619204 |         0.75
 February | NV          | 838039 |            1
 January  | OR          | 446528 |            0
 January  | IA          | 474501 |         0.25
 January  | DC          | 628496 |          0.5
 January  | WI          | 679382 |         0.75
 January  | NV          | 871824 |            1
 March    | IA          | 460282 |            0
 March    | OR          | 481935 |         0.25
 March    | DC          | 716063 |          0.5
 March    | WI          | 771575 |         0.75
 March    | NV          | 970878 |            1
(15 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example calculates, for each employee, the percent rank of the employee&#39;s salary by their job title:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT job_title, employee_last_name, annual_salary,
       PERCENT_RANK()
      OVER (PARTITION BY job_title ORDER BY annual_salary DESC) AS percent_rank
   FROM employee_dimension
   ORDER BY percent_rank, annual_salary;
     job_title      | employee_last_name | annual_salary |    percent_rank
--------------------+--------------------+---------------+---------------------
 Cashier            | Fortin             |          3196 |                   0
 Delivery Person    | Garnett            |          3196 |                   0
 Cashier            | Vogel              |          3196 |                   0
 Customer Service   | Sanchez            |          3198 |                   0
 Shelf Stocker      | Jones              |          3198 |                   0
 Custodian          | Li                 |          3198 |                   0
 Customer Service   | Kramer             |          3198 |                   0
 Greeter            | McNulty            |          3198 |                   0
 Greeter            | Greenwood          |          3198 |                   0
 Shift Manager      | Miller             |         99817 |                   0
 Advertising        | Vu                 |         99853 |                   0
 Branch Manager     | Jackson            |         99858 |                   0
 Marketing          | Taylor             |         99928 |                   0
 Assistant Director | King               |         99973 |                   0
 Sales              | Kramer             |         99973 |                   0
 Head of PR         | Goldberg           |        199067 |                   0
 Regional Manager   | Gauthier           |        199744 |                   0
 Director of HR     | Moore              |        199896 |                   0
 Head of Marketing  | Overstreet         |        199955 |                   0
 VP of Advertising  | Meyer              |        199975 |                   0
 VP of Sales        | Sanchez            |        199992 |                   0
 Founder            | Gauthier           |        927335 |                   0
 CEO                | Taylor             |        953373 |                   0
 Investor           | Garnett            |        963104 |                   0
 Co-Founder         | Vu                 |        977716 |                   0
 CFO                | Vogel              |        983634 |                   0
 President          | Sanchez            |        992363 |                   0
 Delivery Person    | Li                 |          3194 | 0.00114155251141553
 Delivery Person    | Robinson           |          3194 | 0.00114155251141553
 Custodian          | McCabe             |          3192 | 0.00126582278481013
 Shelf Stocker      | Moore              |          3196 | 0.00128040973111396
 Branch Manager     | Moore              |         99716 | 0.00186567164179104
...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/cume-dist-analytic/#&#34;&gt;CUME_DIST [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: PERCENTILE_CONT [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/percentile-cont-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/percentile-cont-analytic/</guid>
      <description>
        
        
        &lt;p&gt;An inverse distribution function where, for each row, PERCENTILE_CONT returns the value that would fall into the specified percentile among a set of values in each partition within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. For example, if the argument to the function is 0.5, the result of the function is the median of the data set (50th percentile). PERCENTILE_CONT assumes a continuous distribution data model. NULL values are ignored.&lt;/p&gt;
&lt;p&gt;PERCENTILE_CONT computes the percentile by first computing the row number where the percentile row would exist. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt; = 1 + &lt;span class=&#34;code-variable&#34;&gt;percentile-value&lt;/span&gt; * (&lt;span class=&#34;code-variable&#34;&gt;num-partition-rows&lt;/span&gt; -1)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If &lt;em&gt;&lt;code&gt;row-number&lt;/code&gt;&lt;/em&gt; is a whole number (within an error of 0.00001), the percentile is the value of row &lt;em&gt;&lt;code&gt;row-number&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Otherwise, OpenText™ Analytics Database interpolates the percentile value between the value of the &lt;code&gt;CEILING(&lt;/code&gt;&lt;em&gt;&lt;code&gt;row-number&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt; row and the value of the &lt;code&gt;FLOOR(&lt;/code&gt;&lt;em&gt;&lt;code&gt;row-number&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt; row. In other words, the percentile is calculated as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  ( CEILING(&lt;span class=&#34;code-variable&#34;&gt; row-number&lt;/span&gt;) - &lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt; ) * ( &lt;span class=&#34;code-variable&#34;&gt;value of &lt;/span&gt;FLOOR(&lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt;)&lt;span class=&#34;code-variable&#34;&gt; row&lt;/span&gt; )
+ ( &lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt; - FLOOR(&lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt;) ) * ( &lt;span class=&#34;code-variable&#34;&gt;value of &lt;/span&gt;CEILING(&lt;span class=&#34;code-variable&#34;&gt;row-number&lt;/span&gt;)&lt;span class=&#34;code-variable&#34;&gt; row&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

If the percentile value is 0.5, PERCENTILE_CONT returns the same result set as the function &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/median-analytic/&#34;&gt;MEDIAN&lt;/a&gt;.

&lt;/div&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;PERCENTILE_CONT ( &lt;span class=&#34;code-variable&#34;&gt;percentile&lt;/span&gt; ) WITHIN GROUP ( ORDER BY &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ ASC | DESC ] ) OVER ( [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;percentile&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Percentile value, a FLOAT constant that ranges from 0 to 1 (inclusive).&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;WITHIN GROUP (ORDER BY &lt;/code&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies how to sort data within each group. ORDER BY takes only one column/expression that must be INTEGER, FLOAT, INTERVAL, or NUMERIC data type. NULL values are discarded.
&lt;p&gt;The &lt;code&gt;WITHIN GROUP(ORDER BY)&lt;/code&gt; clause does not guarantee the order of the SQL result. To order the final result , use the SQL &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY&lt;/a&gt; clause set.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;ASC | DESC&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the ordering sequence as ascending (default) or descending.
&lt;p&gt;Specifying ASC or DESC in the &lt;code&gt;WITHIN GROUP&lt;/code&gt; clause affects results as long as the &lt;em&gt;&lt;code&gt;percentile&lt;/code&gt;&lt;/em&gt; is not &lt;code&gt;0.5&lt;/code&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;This query computes the median annual income per group for the first 300 customers in Wisconsin and the District of Columbia.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_state, customer_key, annual_income, PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY annual_income)
      OVER (PARTITION BY customer_state) AS PERCENTILE_CONT
   FROM customer_dimension WHERE customer_state IN (&amp;#39;DC&amp;#39;,&amp;#39;WI&amp;#39;) AND customer_key &amp;lt; 300
   ORDER BY customer_state, customer_key;
 customer_state | customer_key | annual_income | PERCENTILE_CONT
----------------+--------------+---------------+-----------------
 DC             |           52 |        168312 |        483266.5
 DC             |          118 |        798221 |        483266.5
 WI             |           62 |        283043 |          377691
 WI             |          139 |        472339 |          377691
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This query computes the median annual income per group for all customers in Wisconsin and the District of Columbia.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_state, customer_key, annual_income, PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY annual_income)
      OVER (PARTITION BY customer_state) AS PERCENTILE_CONT
   FROM customer_dimension WHERE customer_state IN (&amp;#39;DC&amp;#39;,&amp;#39;WI&amp;#39;) ORDER BY customer_state, customer_key;
 customer_state | customer_key | annual_income | PERCENTILE_CONT
----------------+--------------+---------------+-----------------
 DC             |           52 |        168312 |        483266.5
 DC             |          118 |        798221 |        483266.5
 DC             |          622 |        220782 |          555088
 DC             |          951 |        178453 |          555088
 DC             |          972 |        961582 |          555088
 DC             |         1286 |        760445 |          555088
 DC             |         1434 |         44836 |          555088
 ...

 WI             |           62 |        283043 |          377691
 WI             |          139 |        472339 |          377691
 WI             |          359 |         42242 |          517717
 WI             |          364 |        867543 |          517717
 WI             |          403 |        509031 |          517717
 WI             |          455 |         32000 |          517717
 WI             |          485 |        373129 |          517717
 ...

(1353 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/median-analytic/#&#34;&gt;MEDIAN [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: PERCENTILE_DISC [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/percentile-disc-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/percentile-disc-analytic/</guid>
      <description>
        
        
        &lt;p&gt;An inverse distribution function where, for each row, &lt;code&gt;PERCENTILE_DISC&lt;/code&gt; returns the value that would fall into the specified percentile among a set of values in each partition within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. &lt;code&gt;PERCENTILE_DISC()&lt;/code&gt; assumes a discrete distribution data model. &lt;code&gt;NULL&lt;/code&gt; values are ignored.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;PERCENTILE_DISC&lt;/code&gt; examines the cumulative distribution values in each group until it finds one that is greater than or equal to the specified percentile. OpenText™ Analytics Database computes the percentile where, for each row, &lt;code&gt;PERCENTILE_DISC&lt;/code&gt; outputs the first value of the &lt;code&gt;WITHIN GROUP(ORDER BY)&lt;/code&gt; column whose &lt;code&gt;CUME_DIST&lt;/code&gt; (cumulative distribution) value is &amp;gt;= the argument &lt;code&gt;FLOAT&lt;/code&gt; value—for example, &lt;code&gt;0.4&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;PERCENTILE_DIST(0.4) WITHIN GROUP (ORDER BY salary) OVER(PARTITION BY deptno)...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Given the following query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT CUME_DIST() OVER(ORDER BY salary) FROM &lt;span class=&#34;code-variable&#34;&gt;table-name&lt;/span&gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The smallest &lt;code&gt;CUME_DIST&lt;/code&gt; value that is greater than 0.4 is also the &lt;code&gt;PERCENTILE_DISC&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;PERCENTILE_DISC ( &lt;span class=&#34;code-variable&#34;&gt;percentile&lt;/span&gt; ) WITHIN GROUP (
    ORDER BY &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ ASC | DESC ] ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;percentile&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Percentile value, a &lt;code&gt;FLOAT&lt;/code&gt; constant that ranges from 0 to 1 (inclusive).&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;WITHIN GROUP(ORDER BY &lt;/code&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies how to sort data within each group. &lt;code&gt;ORDER BY&lt;/code&gt; takes only one column/expression that must be &lt;code&gt;INTEGER&lt;/code&gt;, &lt;code&gt;FLOAT&lt;/code&gt;, &lt;code&gt;INTERVAL&lt;/code&gt;, or &lt;code&gt;NUMERIC&lt;/code&gt; data type. &lt;code&gt;NULL&lt;/code&gt; values are discarded.
&lt;p&gt;The &lt;code&gt;WITHIN GROUP(ORDER BY)&lt;/code&gt; clause does not guarantee the order of the SQL result. To order the final result , use the SQL 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/#&#34;&gt;ORDER BY&lt;/a&gt;&lt;/code&gt; clause set.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;ASC | DESC&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the ordering sequence as ascending (default) or descending.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;This query computes the 20th percentile annual income by group for first 300 customers in Wisconsin and the District of Columbia.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_state, customer_key, annual_income,
      PERCENTILE_DISC(.2) WITHIN GROUP(ORDER BY annual_income)
      OVER (PARTITION BY customer_state) AS PERCENTILE_DISC
   FROM customer_dimension
   WHERE customer_state IN (&amp;#39;DC&amp;#39;,&amp;#39;WI&amp;#39;)
   AND customer_key &amp;lt; 300
   ORDER BY customer_state, customer_key;
 customer_state | customer_key | annual_income | PERCENTILE_DISC
----------------+--------------+---------------+-----------------
 DC             |          104 |        658383 |          417092
 DC             |          168 |        417092 |          417092
 DC             |          245 |        670205 |          417092
 WI             |          106 |        227279 |          227279
 WI             |          127 |        703889 |          227279
 WI             |          209 |        458607 |          227279
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/cume-dist-analytic/#&#34;&gt;CUME_DIST [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-cont-analytic/#&#34;&gt;PERCENTILE_CONT [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: RANK [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/rank-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/rank-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Within each window partition, ranks all rows in the query results set according to the order specified by the window&#39;s &lt;code&gt;ORDER BY&lt;/code&gt; clause.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;RANK&lt;/code&gt; executes as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Sorts partition rows as specified by the &lt;code&gt;ORDER BY&lt;/code&gt; clause.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Compares the &lt;code&gt;ORDER BY&lt;/code&gt; values of the preceding row and current row and ranks the current row as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If &lt;code&gt;ORDER BY&lt;/code&gt; values are the same, the current row gets the same ranking as the preceding row.&lt;/p&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Null values are considered equal. For detailed information on how null values are sorted, see &lt;a href=&#34;../../../../en/data-analysis/query-optimization/analytic-functions/null-sort-order/#&#34;&gt;NULL sort order&lt;/a&gt;.

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the &lt;code&gt;ORDER BY&lt;/code&gt; values are different, &lt;code&gt;DENSE_RANK&lt;/code&gt; increments or decrements the current row&#39;s ranking by 1, plus the number of consecutive duplicate values in the rows that precede it.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The largest rank value is the equal to the total number of rows returned by the query.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;RANK() OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;compared-with-dense_rank&#34;&gt;Compared with DENSE_RANK&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;RANK&lt;/code&gt; can leave gaps in the ranking sequence, while 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/dense-rank-analytic/#&#34;&gt;DENSE_RANK&lt;/a&gt;&lt;/code&gt; does not.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query ranks by state all company customers that have been customers since 2007. In rows where the &lt;code&gt;customer_since&lt;/code&gt; dates are the same, &lt;code&gt;RANK&lt;/code&gt; assigns the rows equal ranking. When the &lt;code&gt;customer_since&lt;/code&gt; date changes, &lt;code&gt;RANK&lt;/code&gt; skips one or more rankings—for example, within &lt;code&gt;CA&lt;/code&gt;, from 12 to 14, and from 17 to 19.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT customer_state, customer_name, customer_since,
    RANK() OVER (PARTITION BY customer_state ORDER BY customer_since) AS rank
    FROM customer_dimension WHERE customer_type=&amp;#39;Company&amp;#39; AND customer_since &amp;gt; &amp;#39;01/01/2007&amp;#39;
    ORDER BY customer_state;
  customer_state | customer_name | customer_since | rank
----------------+---------------+----------------+------
 AZ             | Foodshop      | 2007-01-20     |    1
 AZ             | Goldstar      | 2007-08-11     |    2
 CA             | Metahope      | 2007-01-05     |    1
 CA             | Foodgen       | 2007-02-05     |    2
 CA             | Infohope      | 2007-02-09     |    3
 CA             | Foodcom       | 2007-02-19     |    4
 CA             | Amerihope     | 2007-02-22     |    5
 CA             | Infostar      | 2007-03-05     |    6
 CA             | Intracare     | 2007-03-14     |    7
 CA             | Infocare      | 2007-04-07     |    8
 ...
 CO             | Goldtech      | 2007-02-19     |    1
 CT             | Foodmedia     | 2007-02-11     |    1
 CT             | Metatech      | 2007-02-20     |    2
 CT             | Infocorp      | 2007-04-10     |    3
 ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: ROW_NUMBER [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/row-number-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/row-number-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Assigns a sequence of unique numbers to each row in a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt; partition, starting with 1. ROW_NUMBER and &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/rank-analytic/&#34;&gt;RANK&lt;/a&gt; are generally interchangeable, with the following differences:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;ROW_NUMBER assigns a unique ordinal number to each row in the ordered set, starting with 1.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ROW_NUMBER() is an OpenText™ Analytics Database extension, while RANK conforms to the SQL-99 standard.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ROW_NUMBER () OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following ROW_NUMBER query partitions customers in the VMart table &lt;code&gt;customer_dimension&lt;/code&gt; by &lt;code&gt;customer_regio&lt;/code&gt;n. Within each partition, the function ranks those customers in order of seniority, as specified by its window order clause:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM
    (SELECT ROW_NUMBER() OVER (PARTITION BY customer_region ORDER BY customer_since) AS most_senior,
     customer_region, customer_name, customer_since FROM public.customer_dimension WHERE customer_type = &amp;#39;Individual&amp;#39;) sq
   WHERE most_senior &amp;lt;= 5;
 most_senior | customer_region |    customer_name     | customer_since
-------------+-----------------+----------------------+----------------
           1 | West            | Jack Y. Perkins      | 1965-01-01
           2 | West            | Linda Q. Winkler     | 1965-01-02
           3 | West            | Marcus K. Li         | 1965-01-03
           4 | West            | Carla R. Jones       | 1965-01-07
           5 | West            | Seth P. Young        | 1965-01-09
           1 | East            | Kim O. Vu            | 1965-01-01
           2 | East            | Alexandra L. Weaver  | 1965-01-02
           3 | East            | Steve L. Webber      | 1965-01-04
           4 | East            | Thom Y. Li           | 1965-01-05
           5 | East            | Martha B. Farmer     | 1965-01-07
           1 | SouthWest       | Martha V. Gauthier   | 1965-01-01
           2 | SouthWest       | Jessica U. Goldberg  | 1965-01-07
           3 | SouthWest       | Robert O. Stein      | 1965-01-07
           4 | SouthWest       | Emily I. McCabe      | 1965-01-18
           5 | SouthWest       | Jack E. Miller       | 1965-01-25
           1 | NorthWest       | Julie O. Greenwood   | 1965-01-08
           2 | NorthWest       | Amy X. McNulty       | 1965-01-25
           3 | NorthWest       | Kevin S. Carcetti    | 1965-02-09
           4 | NorthWest       | Sam K. Carcetti      | 1965-03-16
           5 | NorthWest       | Alexandra X. Winkler | 1965-04-05
           1 | MidWest         | Michael Y. Meyer     | 1965-01-01
           2 | MidWest         | Joanna W. Bauer      | 1965-01-06
           3 | MidWest         | Amy E. Harris        | 1965-01-08
           4 | MidWest         | Julie W. McCabe      | 1965-01-09
           5 | MidWest         | William . Peterson   | 1965-01-09
           1 | South           | Dean . Martin        | 1965-01-01
           2 | South           | Ruth U. Williams     | 1965-01-02
           3 | South           | Steve Y. Farmer      | 1965-01-03
           4 | South           | Mark V. King         | 1965-01-08
           5 | South           | Lucas Y. Young       | 1965-01-10
(30 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/rank-analytic/#&#34;&gt;RANK [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: STDDEV [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/stddev-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/stddev-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Computes the statistical sample standard deviation of the current row with respect to the group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. &lt;code&gt;STDDEV_SAMP&lt;/code&gt; returns the same value as the square root of the variance defined for the 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/var-samp-analytic/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt; function:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;STDDEV( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) = SQRT(VAR_SAMP( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When &lt;code&gt;VAR_SAMP&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;, this function returns &lt;code&gt;NULL&lt;/code&gt;.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The nonstandard function &lt;code&gt;STDDEV&lt;/code&gt; is provided for compatibility with other databases. It is semantically identical to
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/stddev-samp-analytic/#&#34;&gt;STDDEV_SAMP&lt;/a&gt;&lt;/code&gt;.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;STDDEV ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the standard deviations of salaries in the employee dimension table by job title Assistant Director:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name, annual_salary,
       STDDEV(annual_salary) OVER (ORDER BY hire_date) as &amp;#34;stddev&amp;#34;
   FROM employee_dimension
   WHERE job_title =  &amp;#39;Assistant Director&amp;#39;;
 employee_last_name | annual_salary |      stddev
--------------------+---------------+------------------
 Bauer              |         85003 |              NaN
 Reyes              |         91051 | 4276.58181261624
 Overstreet         |         53296 | 20278.6923394976
 Gauthier           |         97216 | 19543.7184537642
 Jones              |         82320 | 16928.0764028285
 Fortin             |         56166 | 18400.2738421652
 Carcetti           |         71135 | 16968.9453554483
 Weaver             |         74419 | 15729.0709901852
 Stein              |         85689 | 15040.5909495309
 McNulty            |         69423 | 14401.1524291943
 Webber             |         99091 | 15256.3160166536
 Meyer              |         74774 | 14588.6126417355
 Garnett            |         82169 | 14008.7223268494
 Roy                |         76974 | 13466.1270356647
 Dobisz             |         83486 | 13040.4887828347
 Martin             |         99702 | 13637.6804131055
 Martin             |         73589 | 13299.2838158566
 ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-aggregate/#&#34;&gt;STDDEV [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-samp-aggregate/#&#34;&gt;STDDEV_SAMP [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/stddev-samp-analytic/#&#34;&gt;STDDEV_SAMP [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: STDDEV_POP [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/stddev-pop-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/stddev-pop-analytic/</guid>
      <description>
        
        
        &lt;p&gt;
Computes the statistical population standard deviation and returns the square root of the population variance within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. The &lt;code&gt;STDDEV_POP()&lt;/code&gt; return value is the same as the square root of the &lt;code&gt;VAR_POP()&lt;/code&gt; function:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;STDDEV_POP( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) = SQRT(VAR_POP( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When &lt;code&gt;VAR_POP&lt;/code&gt; returns null, &lt;code&gt;STDDEV_POP&lt;/code&gt; returns null.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;STDDEV_POP ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions.&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the population standard deviations of salaries in the employee dimension table by job title Assistant Director:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name, annual_salary,
       STDDEV_POP(annual_salary) OVER (ORDER BY hire_date) as &amp;#34;stddev_pop&amp;#34;
   FROM employee_dimension WHERE job_title =  &amp;#39;Assistant Director&amp;#39;;
 employee_last_name | annual_salary |    stddev_pop
--------------------+---------------+------------------
 Goldberg           |         61859 |                0
 Miller             |         79582 |           8861.5
 Goldberg           |         74236 | 7422.74712548456
 Campbell           |         66426 | 6850.22125098891
 Moore              |         66630 | 6322.08223926257
 Nguyen             |         53530 | 8356.55480080699
 Harris             |         74115 | 8122.72288970008
 Lang               |         59981 | 8053.54776538731
 Farmer             |         60597 | 7858.70140687825
 Nguyen             |         78941 | 8360.63150784682
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-pop-aggregate/#&#34;&gt;STDDEV_POP [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: STDDEV_SAMP [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/stddev-samp-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/stddev-samp-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Computes the statistical sample standard deviation of the current row with respect to the group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. &lt;code&gt;STDDEV_SAM&lt;/code&gt;&#39;s return value is the same as the square root of the variance defined for the &lt;code&gt;VAR_SAMP&lt;/code&gt; function:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;STDDEV( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) = SQRT(VAR_SAMP( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When &lt;code&gt;VAR_SAMP&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;, &lt;code&gt;STDDEV_SAMP&lt;/code&gt; returns NULL.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

&lt;code&gt;STDDEV_SAMP()&lt;/code&gt; is semantically identical to the nonstandard function, &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-aggregate/&#34;&gt;&lt;code&gt;STDDEV()&lt;/code&gt;&lt;/a&gt;.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;STDDEV_SAMP ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument..&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the sample standard deviations of salaries in the &lt;code&gt;employee&lt;/code&gt; dimension table by job title Assistant Director:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT employee_last_name, annual_salary,
      STDDEV(annual_salary) OVER (ORDER BY hire_date) as &amp;#34;stddev_samp&amp;#34;
      FROM employee_dimension WHERE job_title =  &amp;#39;Assistant Director&amp;#39;;
 employee_last_name | annual_salary |   stddev_samp
--------------------+---------------+------------------
 Bauer              |         85003 |              NaN
 Reyes              |         91051 | 4276.58181261624
 Overstreet         |         53296 | 20278.6923394976
 Gauthier           |         97216 | 19543.7184537642
 Jones              |         82320 | 16928.0764028285
 Fortin             |         56166 | 18400.2738421652
 Carcetti           |         71135 | 16968.9453554483
 Weaver             |         74419 | 15729.0709901852
 Stein              |         85689 | 15040.5909495309
 McNulty            |         69423 | 14401.1524291943
 Webber             |         99091 | 15256.3160166536
 Meyer              |         74774 | 14588.6126417355
 Garnett            |         82169 | 14008.7223268494
 Roy                |         76974 | 13466.1270356647
 Dobisz             |         83486 | 13040.4887828347
 ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/#&#34;&gt;Analytic functions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/stddev-analytic/#&#34;&gt;STDDEV [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-aggregate/#&#34;&gt;STDDEV [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-samp-aggregate/#&#34;&gt;STDDEV_SAMP [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: SUM [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/sum-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/sum-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Computes the sum of an expression over a group of rows within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. It returns a &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; value for a floating-point expression. Otherwise, the return value is the same as the expression data type.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SUM ( &lt;span class=&#34;code-variable&#34;&gt;expression &lt;/span&gt;) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;overflow-handling&#34;&gt;Overflow handling&lt;/h2&gt;
&lt;p&gt;If you encounter data overflow when using &lt;code&gt;SUM&lt;/code&gt;, use 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/sum-float-aggregate/#&#34;&gt;SUM_FLOAT&lt;/a&gt;&lt;/code&gt; which converts data to a floating point.
&lt;p&gt;By default, OpenText™ Analytics Database allows silent numeric overflow when you call this function on numeric data types. For more information on this behavior and how to change it, see&lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/numeric-data-type-overflow-with-sum-sum-float-and-avg/#&#34;&gt;Numeric data type overflow with SUM, SUM_FLOAT, and AVG&lt;/a&gt;.&lt;/p&gt;
&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query returns the cumulative sum all of the returns made to stores in January:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT calendar_month_name AS month, transaction_type, sales_quantity,
     SUM(sales_quantity)
     OVER (PARTITION BY calendar_month_name ORDER BY date_dimension.date_key) AS SUM
     FROM store.store_sales_fact JOIN date_dimension
     USING(date_key) WHERE calendar_month_name IN (&amp;#39;January&amp;#39;)
     AND transaction_type= &amp;#39;return&amp;#39;;
  month  | transaction_type | sales_quantity | SUM
---------+------------------+----------------+------
 January | return           |              7 |  651
 January | return           |              3 |  651
 January | return           |              7 |  651
 January | return           |              7 |  651
 January | return           |              7 |  651
 January | return           |              3 |  651
 January | return           |              7 |  651
 January | return           |              5 |  651
 January | return           |              1 |  651
 January | return           |              6 |  651
 January | return           |              6 |  651
 January | return           |              3 |  651
 January | return           |              9 |  651
 January | return           |              7 |  651
 January | return           |              6 |  651
 January | return           |              8 |  651
 January | return           |              7 |  651
 January | return           |              2 |  651
 January | return           |              4 |  651
 January | return           |              5 |  651
 January | return           |              7 |  651
 January | return           |              8 |  651
 January | return           |              4 |  651
 January | return           |             10 |  651
 January | return           |              6 |  651
 ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/sum-aggregate/#&#34;&gt;SUM [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/#&#34;&gt;Numeric data types&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VAR_POP [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/var-pop-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/var-pop-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the statistical population variance of a non-null set of numbers (nulls are ignored) in a group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. Results are calculated by the sum of squares of the difference of &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; from the mean of &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;, divided by the number of rows remaining:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;(SUM( &lt;span class=&#34;code-variable&#34;&gt;expression &lt;/span&gt;*&lt;span class=&#34;code-variable&#34;&gt; expression &lt;/span&gt;) - SUM(&lt;span class=&#34;code-variable&#34;&gt; expression &lt;/span&gt; ) * SUM( &lt;span class=&#34;code-variable&#34;&gt; expression&lt;/span&gt; ) /   COUNT(&lt;span class=&#34;code-variable&#34;&gt; expression &lt;/span&gt;)) / COUNT(&lt;span class=&#34;code-variable&#34;&gt; expression &lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VAR_POP ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example calculates the cumulative population in the store orders fact table of sales in January 2007:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT date_ordered,
      VAR_POP(SUM(total_order_cost))
      OVER (ORDER BY date_ordered) &amp;#34;var_pop&amp;#34;
   FROM store.store_orders_fact s
   WHERE date_ordered BETWEEN &amp;#39;2007-01-01&amp;#39; AND &amp;#39;2007-01-31&amp;#39;
   GROUP BY s.date_ordered;
 date_ordered |     var_pop
--------------+------------------
 2007-01-01   |                0
 2007-01-02   |         89870400
 2007-01-03   |       3470302472
 2007-01-04   |  4466755450.6875
 2007-01-05   | 3816904780.80078
 2007-01-06   |   25438212385.25
 2007-01-07   | 22168747513.1016
 2007-01-08   | 23445191012.7344
 2007-01-09   | 39292879603.1113
 2007-01-10   | 48080574326.9609
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-pop-aggregate/#&#34;&gt;VAR_POP [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VAR_SAMP [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/var-samp-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/var-samp-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the sample variance of a non-&lt;code&gt;NULL&lt;/code&gt; set of numbers (&lt;code&gt;NULL&lt;/code&gt; values in the set are ignored) for each row of the group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. Results are calculated as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;(SUM( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; * &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) - SUM( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) * SUM( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) / COUNT( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) )
/ (COUNT( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) - 1 )
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This function and 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/variance-analytic/#&#34;&gt;VARIANCE&lt;/a&gt;&lt;/code&gt; differ in one way: given an input set of one element, &lt;code&gt;VARIANCE&lt;/code&gt; returns 0 and &lt;code&gt;VAR_SAMP&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VAR_SAMP ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;&lt;code&gt;NUMERIC&lt;/code&gt; data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;null-handling&#34;&gt;Null handling&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;VAR_SAMP&lt;/code&gt; returns the sample variance of a set of numbers after it discards the &lt;code&gt;NULL&lt;/code&gt; values in the set.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the function is applied to an empty set, then it returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example calculates the sample variance in the store orders fact table of sales in December 2007:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT date_ordered,
      VAR_SAMP(SUM(total_order_cost))
      OVER (ORDER BY date_ordered) &amp;#34;var_samp&amp;#34;
   FROM store.store_orders_fact s
   WHERE date_ordered BETWEEN &amp;#39;2007-12-01&amp;#39; AND &amp;#39;2007-12-31&amp;#39;
   GROUP BY s.date_ordered;
 date_ordered |     var_samp
--------------+------------------
 2007-12-01   |              NaN
 2007-12-02   |      90642601088
 2007-12-03   | 48030548449.3359
 2007-12-04   | 32740062504.2461
 2007-12-05   | 32100319112.6992
 2007-12-06   |  26274166814.668
 2007-12-07   | 23017490251.9062
 2007-12-08   | 21099374085.1406
 2007-12-09   | 27462205977.9453
 2007-12-10   | 26288687564.1758
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/variance-analytic/#&#34;&gt;VARIANCE [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-samp-aggregate/#&#34;&gt;VAR_SAMP [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VARIANCE [analytic]</title>
      <link>/en/sql-reference/functions/analytic-functions/variance-analytic/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/analytic-functions/variance-analytic/</guid>
      <description>
        
        
        &lt;p&gt;Returns the sample variance of a non-&lt;code&gt;NULL&lt;/code&gt; set of numbers (&lt;code&gt;NULL&lt;/code&gt; values in the set are ignored) for each row of the group within a &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/window-analytic/&#34; title=&#34;An analytic function&amp;#39;s OVER clause specifies how to partition, sort, and frame function input with respect to the current row.&#34;&gt;window&lt;/a&gt;. Results are calculated as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;( SUM( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; * &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) - SUM( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) * SUM( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) / COUNT( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; )) / (COUNT( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) - 1 )
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;VARIANCE&lt;/code&gt; returns the variance of &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;, which is calculated as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;0 if the number of rows in &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; = 1&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/var-samp-analytic/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt; if the number of rows in &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; &amp;gt; 1&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The nonstandard function &lt;code&gt;VARIANCE&lt;/code&gt; is provided for compatibility with other databases. It is semantically identical to
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/var-samp-analytic/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt;.

&lt;/div&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VAR_SAMP ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; ) OVER (
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt; ]
    [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-frame-clause/#&#34;&gt;window-frame-clause&lt;/a&gt;&lt;/span&gt; ] )
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Any &lt;a href=&#34;../../../../en/sql-reference/data-types/numeric-data-types/&#34;&gt;NUMERIC data type&lt;/a&gt; or any non-numeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;OVER()&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/&#34;&gt;Analytic Functions&lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example calculates the cumulative variance in the store orders fact table of sales in December 2007:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT date_ordered,
      VARIANCE(SUM(total_order_cost))
      OVER (ORDER BY date_ordered) &amp;#34;variance&amp;#34;
   FROM store.store_orders_fact s
   WHERE date_ordered BETWEEN &amp;#39;2007-12-01&amp;#39; AND &amp;#39;2007-12-31&amp;#39;
   GROUP BY s.date_ordered;
 date_ordered |     variance
--------------+------------------
 2007-12-01   |              NaN
 2007-12-02   |       2259129762
 2007-12-03   | 1809012182.33301
 2007-12-04   |   35138165568.25
 2007-12-05   | 26644110029.3003
 2007-12-06   |      25943125234
 2007-12-07   | 23178202223.9048
 2007-12-08   | 21940268901.1431
 2007-12-09   | 21487676799.6108
 2007-12-10   | 21521358853.4331
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/var-samp-analytic/#&#34;&gt;VAR_SAMP [analytic]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/variance-aggregate/#&#34;&gt;VARIANCE [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-samp-aggregate/#&#34;&gt;VAR_SAMP [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
  </channel>
</rss>
