<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Aggregate functions</title>
    <link>/en/sql-reference/functions/aggregate-functions/</link>
    <description>Recent content in Aggregate functions on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/sql-reference/functions/aggregate-functions/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Sql-Reference: APPROXIMATE_COUNT_DISTINCT</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct/</guid>
      <description>
        
        
        &lt;p&gt;Returns the number of distinct non-NULL values in a data set.&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;APPROXIMATE_COUNT_DISTINCT ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[, &lt;span class=&#34;code-variable&#34;&gt;error-tolerance&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;Value to be evaluated using any data type that supports equality comparison.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;error-tolerance &lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;Numeric value that represents the desired percentage of error tolerance, distributed around the value returned by this function. The smaller the error tolerance, the closer the approximation.&lt;/p&gt;
&lt;p&gt;You can set &lt;code&gt;error-tolerance&lt;/code&gt; to a minimum value of 0.88. Vertica imposes no maximum restriction, but any value greater than 5 is implemented with 5% error tolerance.&lt;/p&gt;

&lt;p&gt;If you omit this argument, OpenText™ Analytics Database uses an error tolerance of 1.25(%).&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;APPROXIMATE_COUNT_DISTINCT and DISTINCT aggregates cannot be in the same query block.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;ErrorTolerance&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;error-tolerance&#34;&gt;Error tolerance&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;APPROXIMATE_COUNT_DISTINCT(&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;error-tolerance&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt; returns a value equal to &lt;code&gt;COUNT(DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt;, with an error that is lognormally distributed with standard deviation.&lt;/p&gt;
&lt;p&gt;Parameter &lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt; is optional. Supply this argument to specify the desired standard deviation. &lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt; is defined as 2.17 standard deviations, which corresponds to a 97 percent confidence interval:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&lt;span class=&#34;code-variable&#34;&gt;standard-deviation&lt;/span&gt; = &lt;span class=&#34;code-variable&#34;&gt;error-tolerance&lt;/span&gt; / 2.17
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt;&lt;code&gt; = 1&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Default setting, corresponds to a standard deviation&lt;/p&gt;
&lt;p&gt;97 percent of the time, APPROXIMATE_COUNT_DISTINCT(&lt;em&gt;&lt;code&gt;x,5&lt;/code&gt;&lt;/em&gt;) returns a value between:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;COUNT(DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;) * 0.99&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;COUNT(DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;) * 1.01&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt;&lt;code&gt; = 5&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;97 percent of the time, &lt;code&gt;APPROXIMATE_COUNT_DISTINCT(&lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt; returns a value between:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;COUNT(DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;) * 0.95&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;COUNT(DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;) * 1.05&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A 99 percent confidence interval corresponds to &lt;code&gt;2.58&lt;/code&gt; standard deviations. To set &lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt; confidence level corresponding to 99 (instead of a 97) percent , multiply &lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt; by &lt;code&gt;2.17 / 2.58 = 0.841&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For example, if you specify &lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt; as &lt;code&gt;5 * 0.841 = 4.2&lt;/code&gt;, &lt;code&gt;APPROXIMATE_COUNT_DISTINCT(&lt;/code&gt;&lt;em&gt;&lt;code&gt;x,4.2&lt;/code&gt;&lt;/em&gt;&lt;code&gt;)&lt;/code&gt; returns values 99 percent of the time between:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;COUNT (DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;) * 0.95&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;COUNT (DISTINCT &lt;/code&gt;&lt;em&gt;&lt;code&gt;x&lt;/code&gt;&lt;/em&gt;&lt;code&gt;) * 1.05&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;Count the total number of distinct values in column &lt;code&gt;product_key&lt;/code&gt; from table &lt;code&gt;store.store_sales_fact&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT COUNT(DISTINCT product_key) FROM store.store_sales_fact;
 COUNT
-------
 19982
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Count the approximate number of distinct values in &lt;code&gt;product_key&lt;/code&gt; with various error tolerances. The smaller the error tolerance, the closer the approximation:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT APPROXIMATE_COUNT_DISTINCT(product_key,5) AS five_pct_accuracy,
   APPROXIMATE_COUNT_DISTINCT(product_key,1) AS one_pct_accuracy,
   APPROXIMATE_COUNT_DISTINCT(product_key,.88) AS point_eighteight_pct_accuracy
   FROM store.store_sales_fact;

 five_pct_accuracy | one_pct_accuracy | point_eighteight_pct_accuracy
-------------------+------------------+-------------------------------
             19431 |            19921 |                         19921
(1 row)
&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/query-optimization/distinct-select-query-list/approximate-count-distinct-functions/#&#34;&gt;Approximate count distinct functions&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct-of-synopsis/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct-of-synopsis/</guid>
      <description>
        
        
        &lt;p&gt;Calculates the number of distinct non-NULL values from the synopsis objects created by &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct-synopsis/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT_SYNOPSIS&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;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS ( &lt;span class=&#34;code-variable&#34;&gt;synopsis-obj&lt;/span&gt;[, &lt;span class=&#34;code-variable&#34;&gt;error-tolerance&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;synopsis-obj&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A synopsis object created by APPROXIMATE_COUNT_DISTINCT_SYNOPSIS.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;Numeric value that represents the desired percentage of error tolerance, distributed around the value returned by this function. The smaller the error tolerance, the closer the approximation.&lt;/p&gt;
&lt;p&gt;You can set &lt;code&gt;error-tolerance&lt;/code&gt; to a minimum value of 0.88. Vertica imposes no maximum restriction, but any value greater than 5 is implemented with 5% error tolerance.&lt;/p&gt;

&lt;p&gt;If you omit this argument, OpenText™ Analytics Database uses an error tolerance of 1.25(%).&lt;/p&gt;
&lt;p&gt;For more details, see &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS and DISTINCT aggregates cannot be in the same query block.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following examples review and compare different ways to obtain a count of unique values in a table column:&lt;/p&gt;
&lt;p&gt;Return an exact count of unique values in column product_key, from table &lt;code&gt;store.store_sales_fact&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \timing
Timing is on.
=&amp;gt; SELECT &lt;span class=&#34;code-input&#34;&gt;COUNT(DISTINCT product_key)&lt;/span&gt; from store.store_sales_fact;
 count
-------
 19982
(1 row)

Time: First fetch (1 row): 553.033 ms. All rows formatted: 553.075 ms
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Return an approximate count of unique values in column &lt;code&gt;product_key&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT &lt;span class=&#34;code-input&#34;&gt;APPROXIMATE_COUNT_DISTINCT(product_key)&lt;/span&gt; as unique_product_keys
   FROM store.store_sales_fact;
 unique_product_keys
---------------------
               19921
(1 row)

Time: First fetch (1 row): 394.562 ms. All rows formatted: 394.600 ms
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Create a synopsis object that represents a set of &lt;code&gt;store.store_sales_fact&lt;/code&gt; data with unique &lt;code&gt;product_key&lt;/code&gt; values, store the synopsis in the new table &lt;code&gt;my_summary&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; CREATE TABLE my_summary AS SELECT &lt;span class=&#34;code-input&#34;&gt;APPROXIMATE_COUNT_DISTINCT_SYNOPSIS (product_key) syn&lt;/span&gt;
   FROM store.store_sales_fact;
CREATE TABLE
Time: First fetch (0 rows): 582.662 ms. All rows formatted: 582.682 ms
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Return a count from the saved synopsis:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT &lt;span class=&#34;code-input&#34;&gt;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS(syn)&lt;/span&gt; FROM my_summary;
 ApproxCountDistinctOfSynopsis
-------------------------------
                         19921
(1 row)

Time: First fetch (1 row): 105.295 ms. All rows formatted: 105.335 ms
&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/query-optimization/distinct-select-query-list/approximate-count-distinct-functions/#&#34;&gt;Approximate count distinct functions&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: APPROXIMATE_COUNT_DISTINCT_SYNOPSIS</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct-synopsis/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct-synopsis/</guid>
      <description>
        
        
        &lt;p&gt;Summarizes the information of distinct non-NULL values and materializes the result set in a VARBINARY or LONG VARBINARY &lt;em&gt;&lt;code&gt;synopsis&lt;/code&gt;&lt;/em&gt; object. The calculated result is within a specified range of error tolerance. You save the synopsis object in a table for use by &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct-of-synopsis/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS&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;APPROXIMATE_COUNT_DISTINCT_SYNOPSIS ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[, &lt;span class=&#34;code-variable&#34;&gt;error-tolerance&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;Value to evaluate using any data type that supports equality comparison.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;Numeric value that represents the desired percentage of error tolerance, distributed around the value returned by this function. The smaller the error tolerance, the closer the approximation.&lt;/p&gt;
&lt;p&gt;You can set &lt;code&gt;error-tolerance&lt;/code&gt; to a minimum value of 0.88. Vertica imposes no maximum restriction, but any value greater than 5 is implemented with 5% error tolerance.&lt;/p&gt;

&lt;p&gt;If you omit this argument, OpenText™ Analytics Database uses an error tolerance of 1.25(%).&lt;/p&gt;
&lt;p&gt;For more details, see &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT&lt;/a&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;APPROXIMATE_COUNT_DISTINCT_SYNOPSIS and DISTINCT aggregates cannot be in the same query block.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct-of-synopsis/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/data-analysis/query-optimization/distinct-select-query-list/approximate-count-distinct-functions/#&#34;&gt;Approximate count distinct functions&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: APPROXIMATE_COUNT_DISTINCT_SYNOPSIS_MERGE</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct-synopsis-merge/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-count-distinct-synopsis-merge/</guid>
      <description>
        
        
        &lt;p&gt;Aggregates multiple synopses into one new synopsis. This function is similar to &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct-of-synopsis/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS&lt;/a&gt; but returns one synopsis instead of the count estimate. The benefit of this function is that it speeds up final estimation when calling APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS.&lt;/p&gt;
&lt;p&gt;For example, if you need to regularly estimate count distinct of users for a long period of time (such as several years) you can pre-accumulate synopses of days into one synopsis for a year.&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;APPROXIMATE_COUNT_DISTINCT_SYNOPSIS_MERGE ( &lt;span class=&#34;code-variable&#34;&gt;synopsis-obj&lt;/span&gt; [, &lt;span class=&#34;code-variable&#34;&gt;error-tolerance&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;synopsis-obj&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;An expression that can be evaluated to one or more synopses. Typically a &lt;em&gt;&lt;code&gt;synopsis-obj&lt;/code&gt;&lt;/em&gt; is generated as a binary string by either the &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT&lt;/a&gt; or APPROXIMATE_COUNT_DISTINCT_SYNOPSIS_MERGE function and is stored in a table column of type VARBINARY or LONG VARBINARY.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;error-tolerance&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;Numeric value that represents the desired percentage of error tolerance, distributed around the value returned by this function. The smaller the error tolerance, the closer the approximation.&lt;/p&gt;
&lt;p&gt;You can set &lt;code&gt;error-tolerance&lt;/code&gt; to a minimum value of 0.88. Vertica imposes no maximum restriction, but any value greater than 5 is implemented with 5% error tolerance.&lt;/p&gt;

&lt;p&gt;If you omit this argument, OpenText™ Analytics Database uses an error tolerance of 1.25(%).&lt;/p&gt;
&lt;p&gt;For more details, see &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT&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;See &lt;a href=&#34;../../../../en/data-analysis/query-optimization/distinct-select-query-list/approximate-count-distinct-functions/#&#34;&gt;Approximate count distinct functions&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: APPROXIMATE_MEDIAN [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-median-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-median-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Computes the approximate median of an expression over a group of rows. The function returns a FLOAT value.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;APPROXIMATE_MEDIAN&lt;/code&gt; is an alias of &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-percentile-aggregate/#&#34;&gt;APPROXIMATE_PERCENTILE [aggregate]&lt;/a&gt; with a parameter of 0.5.

&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;strong&gt;Note&lt;/strong&gt;: This function is best suited for large groups of data. If you have a small group of data, use the exact &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/median-analytic/#&#34;&gt;MEDIAN [analytic]&lt;/a&gt; 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;APPROXIMATE_MEDIAN ( &lt;span class=&#34;code-variable&#34;&gt;expression&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 FLOAT or INTEGER data type. The function returns the approximate middle value or an interpolated value that would be the approximate middle value once the values are sorted. Null values are ignored in the calculation.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&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;

For optimal performance when using &lt;code&gt;GROUP BY&lt;/code&gt; in your query, verify that your table is sorted on the &lt;code&gt;GROUP BY&lt;/code&gt; column.

&lt;/div&gt;
&lt;p&gt;The following examples uses this table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE allsales(state VARCHAR(20), name VARCHAR(20), sales INT) ORDER BY state;
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;A&amp;#39;, 60);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;B&amp;#39;, 20);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;C&amp;#39;, 15);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;D&amp;#39;, 20);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;E&amp;#39;, 50);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;F&amp;#39;, 40);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;G&amp;#39;, 10);
COMMIT;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Calculate the approximate median of all sales in this table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT APPROXIMATE_MEDIAN (sales) FROM allsales;
APROXIMATE_MEDIAN
--------------------
                 20
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Modify the query to group sales by state, and obtain the approximate median for each one:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT state, APPROXIMATE_MEDIAN(sales) FROM allsales GROUP BY state;
 state | APPROXIMATE_MEDIAN
-------+--------------------
 MA    |                 35
 NY    |                 20
(2 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/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/aggregate-functions/approximate-percentile-aggregate/#&#34;&gt;APPROXIMATE_PERCENTILE [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: APPROXIMATE_PERCENTILE [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-percentile-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-percentile-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Computes the approximate percentile of an expression over a group of rows. This function returns a FLOAT value.&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;

&lt;strong&gt;Note&lt;/strong&gt;: Use this function when many rows are aggregated into groups. If the number of aggregated rows is small, use the analytic function &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-cont-analytic/&#34;&gt;PERCENTILE_CONT&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;APPROXIMATE_PERCENTILE ( &lt;span class=&#34;code-variable&#34;&gt;column-expression&lt;/span&gt; USING PARAMETERS percentiles=&amp;#39;&lt;span class=&#34;code-variable&#34;&gt;percentile-values&lt;/span&gt;&amp;#39; )
&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;column-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A column of FLOAT or INTEGER data types whose percentiles will be calculated. NULL values are ignored.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;percentiles&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;One or more (up to 1000) comma-separated &lt;code&gt;FLOAT&lt;/code&gt; constants ranging from 0 to 1 inclusive, specifying the percentile values to be calculated.&lt;/dd&gt;
&lt;/dl&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;

&lt;strong&gt;Note&lt;/strong&gt;: The deprecated parameter &lt;code&gt;percentile&lt;/code&gt;, which takes only a single float, continues to be supported for backwards-compatibility.

&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&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;

For optimal performance when using &lt;code&gt;GROUP BY&lt;/code&gt; in your query, verify that your table is sorted on the &lt;code&gt;GROUP BY&lt;/code&gt; column.

&lt;/div&gt;
&lt;p&gt;The following examples use this table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE allsales(state VARCHAR(20), name VARCHAR(20), sales INT) ORDER BY state;
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;A&amp;#39;, 60);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;B&amp;#39;, 20);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;C&amp;#39;, 15);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;D&amp;#39;, 20);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;E&amp;#39;, 50);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;F&amp;#39;, 40);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;G&amp;#39;, 10);
COMMIT;

=&amp;gt; SELECT * FROM allsales;
 state | name | sales
-------+------+-------
 MA    | A    |    60
 NY    | B    |    20
 NY    | C    |    15
 NY    | F    |    40
 MA    | D    |    20
 MA    | E    |    50
 MA    | G    |    10
(7 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Calculate the approximate percentile for sales in each state:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT state, APPROXIMATE_PERCENTILE(sales USING PARAMETERS percentiles=&amp;#39;0.5&amp;#39;) AS median
FROM allsales GROUP BY state;
 state | median
-------+--------
 MA    |     35
 NY    |     20
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Calculate multiple approximate percentiles for sales in each state:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT state, APPROXIMATE_PERCENTILE(sales USING PARAMETERS percentiles=&amp;#39;0.5,1.0&amp;#39;)
FROM allsales GROUP BY state;
 state | APPROXIMATE_PERCENTILE
-------+--------
 MA    |     [35.0,60.0]
 NY    |     [20.0,40.0]
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Calculate multiple approximate percentiles for sales in each state and show results for each percentile in separate columns:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ps[0] as q0, ps[1] as q1, ps[2] as q2, ps[3] as q3, ps[4] as q4
FROM (SELECT APPROXIMATE_PERCENTILE(sales USING PARAMETERS percentiles=&amp;#39;0, 0.25, 0.5, 0.75, 1&amp;#39;)
AS ps FROM allsales GROUP BY state) as s1;
  q0  |  q1  |  q2  |  q3  |  q4
------+------+------+------+------
 10.0 | 17.5 | 35.0 | 52.5 | 60.0
 15.0 | 17.5 | 20.0 | 30.0 | 40.0
(2 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/approximate-quantiles/#&#34;&gt;APPROXIMATE_QUANTILES&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/median-analytic/&#34;&gt;MEDIAN&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/percentile-cont-analytic/&#34;&gt;PERCENTILE_CONT&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: APPROXIMATE_QUANTILES</title>
      <link>/en/sql-reference/functions/aggregate-functions/approximate-quantiles/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/approximate-quantiles/</guid>
      <description>
        
        
        &lt;p&gt;Computes an array of weighted, approximate percentiles of a column within some user-specified error. This algorithm is similar to &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-percentile-aggregate/#&#34;&gt;APPROXIMATE_PERCENTILE [aggregate]&lt;/a&gt;, which instead returns a single percentile.&lt;/p&gt;
&lt;p&gt;The performance of this function depends entirely on the specified epsilon and the size of the provided array.&lt;/p&gt;
&lt;p&gt;The OVER clause for this function must be 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;APPROXIMATE_QUANTILES ( &lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt; USING PARAMETERS [nquantiles=&lt;span class=&#34;code-variable&#34;&gt;n&lt;/span&gt;], [epsilon=&lt;span class=&#34;code-variable&#34;&gt;error&lt;/span&gt;] ) OVER() FROM &lt;span class=&#34;code-variable&#34;&gt;table&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;column&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The &lt;code&gt;INTEGER&lt;/code&gt; or &lt;code&gt;FLOAT&lt;/code&gt; column for which to calculate the percentiles. NULL values are ignored.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;An integer that specifies the number of desired quantiles in the returned array.
&lt;p&gt;&lt;strong&gt;Default:&lt;/strong&gt; 11&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;error&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The allowed error for any returned percentile. Specifically, for an array of size &lt;em&gt;N&lt;/em&gt;, the specified error ε (epsilon) for the φ-quantile guarantees that the rank &lt;em&gt;r&lt;/em&gt; of the return value with respect to the rank ⌊φN⌋ of the exact value is such that:
&lt;p&gt;⌊(φ-ε)N⌋ ≤ r ≤ ⌊(φ+ε)N⌋&lt;/p&gt;
&lt;p&gt;For &lt;em&gt;n&lt;/em&gt; quantiles, if the error ε is specified such that ε &amp;gt; 1/n, this function will return non-deterministic results.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default:&lt;/strong&gt; 0.001&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;table&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The table containing &lt;em&gt;&lt;code&gt;column&lt;/code&gt;&lt;/em&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 this table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE allsales(state VARCHAR(20), name VARCHAR(20), sales INT) ORDER BY state;
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;A&amp;#39;, 60);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;B&amp;#39;, 20);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;C&amp;#39;, 15);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;D&amp;#39;, 20);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;E&amp;#39;, 50);
INSERT INTO allsales VALUES(&amp;#39;NY&amp;#39;, &amp;#39;F&amp;#39;, 40);
INSERT INTO allsales VALUES(&amp;#39;MA&amp;#39;, &amp;#39;G&amp;#39;, 10);
COMMIT;

=&amp;gt; SELECT * FROM allsales;
 state | name | sales
-------+------+-------
 MA    | A    |    60
 NY    | B    |    20
 NY    | C    |    15
 NY    | F    |    40
 MA    | D    |    20
 MA    | E    |    50
 MA    | G    |    10
(7 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This call to APPROXIMATE_QUANTILES returns a 6-element array of approximate percentiles, one for each quantile. Each quantile relates to the percentile by a factor of 100. For example, the second entry in the output indicates that 15 is the 0.2-quantile of the input column, so 15 is the 20th percentile of the input column.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT APPROXIMATE_QUANTILES(sales USING PARAMETERS nquantiles=6) OVER() FROM allsales;
 Quantile | Value
----------+-------
        0 |    10
      0.2 |    15
      0.4 |    20
      0.6 |    40
      0.8 |    50
        1 |    60
(6 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: ARGMAX_AGG</title>
      <link>/en/sql-reference/functions/aggregate-functions/argmax-agg/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/argmax-agg/</guid>
      <description>
        
        
        &lt;p&gt;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_AGG finds the row with the highest 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 highest &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; value, ARGMAX_AGG returns &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt; from the first row that it finds. Use the WITHIN GROUP ORDER BY clause to control which row ARGMAX_AGG finds first.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;p&gt;&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt; if the WITHIN GROUP ORDER BY clause specifies a column or set of columns that resolves to unique values within the group; otherwise &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/volatile-functions/&#34; title=&#34;&#34;&gt;Volatile&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ARGMAX_AGG ( &lt;span class=&#34;code-variable&#34;&gt;target&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;arg&lt;/span&gt; ) [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/#&#34;&gt;within-group-order-by-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;

The &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; argument cannot reference a &lt;a href=&#34;../../../../en/sql-reference/data-types/spatial-data-types/&#34;&gt;spatial data type&lt;/a&gt; column, GEOMETRY or GEOGRAPHY.

&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;span class=&#34;code-variable&#34;&gt;[within-group-order-by-clause](/en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/)&lt;/span&gt;&lt;/dt&gt;
&lt;dd&gt;Sorts target values within each group of rows:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITHIN GROUP (ORDER BY { &lt;span class=&#34;code-variable&#34;&gt;column-expression&lt;/span&gt;[ &lt;span class=&#34;code-variable&#34;&gt;sort-qualifiers&lt;/span&gt; ] }[,...])
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;&lt;code&gt;sort-qualifiers&lt;/code&gt;&lt;/em&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;   { ASC | DESC [ NULLS { FIRST | LAST | AUTO } ] }
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use this clause to determine which row is returned when multiple rows contain the highest target value; otherwise, results are likely to vary with each iteration of the same query.

&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;

WITHIN GROUP ORDER BY can consume a large amount of memory per group. To minimize memory consumption, create projections that support &lt;a href=&#34;../../../../en/data-analysis/query-optimization/group-by-queries/group-by-implementation-options/#GROUPBY&#34;&gt;GROUPBY PIPELINED&lt;/a&gt;.

&lt;/div&gt;&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example calls ARGMAX_AGG in a &lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/&#34;&gt;WITH clause&lt;/a&gt; to find which employees in each region are at or near retirement age. If multiple employees within each region have the same age, ARGMAX_AGG chooses the employees with the highest salary level and returns with their IDs. The primary query returns with details on the employees selected from each region:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; WITH r AS (SELECT employee_region, ARGMAX_AGG(employee_age, employee_key)
       WITHIN GROUP (ORDER BY annual_salary DESC) emp_id
       FROM employee_dim GROUP BY employee_region ORDER BY employee_region)
    SELECT r.employee_region, ed.annual_salary AS highest_salary, employee_key,
       ed.employee_first_name||&amp;#39; &amp;#39;||ed.employee_last_name AS employee_name, ed.employee_age
       FROM r JOIN employee_dim ed ON r.emp_id = ed.employee_key ORDER BY ed.employee_region;
         employee_region          | highest_salary | employee_key |  employee_name   | employee_age
----------------------------------+----------------+--------------+------------------+--------------
 East                             |         927335 |           70 | Sally Gauthier   |           65
 MidWest                          |         177716 |          869 | Rebecca McCabe   |           65
 NorthWest                        |         100300 |         7597 | Kim Jefferson    |           65
 South                            |         196454 |          275 | Alexandra Harris |           65
 SouthWest                        |         198669 |         1043 | Seth Stein       |           65
 West                             |         197203 |          681 | Seth Jones       |           65
(6 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/aggregate-functions/argmin-agg/#&#34;&gt;ARGMIN_AGG&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: ARGMIN_AGG</title>
      <link>/en/sql-reference/functions/aggregate-functions/argmin-agg/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/argmin-agg/</guid>
      <description>
        
        
        &lt;p&gt;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_AGG finds the row with the lowest 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 lowest &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; value, ARGMIN_AGG returns &lt;em&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/em&gt; from the first row that it finds. Use the WITHIN GROUP ORDER BY clause to control which row ARGMMIN_AGG finds first.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;p&gt;&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt; if the WITHIN GROUP ORDER BY clause specifies a column or set of columns that resolves to unique values within the group; otherwise &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/volatile-functions/&#34; title=&#34;&#34;&gt;Volatile&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ARGMIN_AGG ( &lt;span class=&#34;code-variable&#34;&gt;target&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;arg&lt;/span&gt; ) [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/#&#34;&gt;within-group-order-by-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;

The &lt;em&gt;&lt;code&gt;target&lt;/code&gt;&lt;/em&gt; argument cannot reference a &lt;a href=&#34;../../../../en/sql-reference/data-types/spatial-data-types/&#34;&gt;spatial data type&lt;/a&gt; column, GEOMETRY or GEOGRAPHY.

&lt;/div&gt;&lt;/dd&gt;
&lt;dt&gt;&lt;span class=&#34;code-variable&#34;&gt;[within-group-order-by-clause](/en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/)&lt;/span&gt;&lt;/dt&gt;
&lt;dd&gt;Sorts target values within each group of rows:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITHIN GROUP (ORDER BY { &lt;span class=&#34;code-variable&#34;&gt;column-expression&lt;/span&gt;[ &lt;span class=&#34;code-variable&#34;&gt;sort-qualifiers&lt;/span&gt; ] }[,...])
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;&lt;code&gt;sort-qualifiers&lt;/code&gt;&lt;/em&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;   { ASC | DESC [ NULLS { FIRST | LAST | AUTO } ] }
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use this clause to determine which row is returned when multiple rows contain the lowest target value; otherwise, results are likely to vary with each iteration of the same query.

&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;

WITHIN GROUP ORDER BY can consume a large amount of memory per group. To minimize memory consumption, create projections that support &lt;a href=&#34;../../../../en/data-analysis/query-optimization/group-by-queries/group-by-implementation-options/#GROUPBY&#34;&gt;GROUPBY PIPELINED&lt;/a&gt;.

&lt;/div&gt;&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example calls ARGMIN_AGG in a &lt;a href=&#34;../../../../en/sql-reference/statements/select/with-clause/&#34;&gt;WITH clause&lt;/a&gt; to find the lowest salary among all employees in each region, and returns with the lowest-paid employee IDs. The primary query returns with the salary amounts and employee names:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; WITH msr (employee_region, emp_id) AS
    (SELECT employee_region, argmin_agg(annual_salary, employee_key) lowest_paid_employee FROM employee_dim GROUP BY employee_region)
    SELECT msr.employee_region, ed.annual_salary AS lowest_salary, ed.employee_first_name||&amp;#39; &amp;#39;||ed.employee_last_name AS employee_name
     FROM msr JOIN employee_dim ed ON msr.emp_id = ed.employee_key ORDER BY annual_salary DESC;
         employee_region          | lowest_salary |  employee_name
----------------------------------+---------------+-----------------
 NorthWest                        |         20913 | Raja Garnett
 SouthWest                        |         20750 | Seth Moore
 West                             |         20443 | Midori Taylor
 South                            |         20363 | David Bauer
 East                             |         20306 | Craig Jefferson
 MidWest                          |         20264 | Dean Vu
(6 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/aggregate-functions/argmax-agg/#&#34;&gt;ARGMAX_AGG&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: AVG [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/avg-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/avg-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Computes the average (arithmetic mean) of an expression over a group of rows. &lt;span class=&#34;sql&#34;&gt;AVG&lt;/span&gt; always returns a &lt;span class=&#34;sql&#34;&gt;DOUBLE PRECISION&lt;/span&gt; value.&lt;/p&gt;
&lt;p&gt;The &lt;span class=&#34;sql&#34;&gt;AVG&lt;/span&gt; aggregate function differs from the &lt;span class=&#34;sql&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/avg-analytic/&#34;&gt;AVG&lt;/a&gt;&lt;/span&gt; analytic function, which computes the average 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;.&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 ( [ ALL | DISTINCT ] &lt;span class=&#34;code-variable&#34;&gt;expression&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;ALL&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Invokes the aggregate function for all rows in the group (default).&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;DISTINCT&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Invokes the aggregate function for all distinct non-null values of the expression found in the group.&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The value whose average is calculated over a set of rows, any expression that can have a &lt;span class=&#34;sql&#34;&gt;DOUBLE PRECISION&lt;/span&gt; result.&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 returns the average income from the &lt;span class=&#34;sql&#34;&gt;customer&lt;/span&gt; table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT AVG(annual_income) FROM customer_dimension;
     AVG
--------------
 2104270.6485
(1 row)
&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/count-aggregate/#&#34;&gt;COUNT [aggregate]&lt;/a&gt;
&lt;/li&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;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BIT_AND</title>
      <link>/en/sql-reference/functions/aggregate-functions/bit-and/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/bit-and/</guid>
      <description>
        
        
        &lt;p&gt;Takes the bitwise AND of all non-null input values. If the input parameter is NULL, the return value is also 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;BIT_AND ( &lt;span class=&#34;code-variable&#34;&gt;expression&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 BINARY or VARBINARY input value to evaluate. BIT_AND operates on VARBINARY types explicitly and on BINARY types implicitly through &lt;a href=&#34;../../../../en/sql-reference/data-types/data-type-coercion-chart/&#34;&gt;casts&lt;/a&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;BIT_AND returns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The same value as the argument data type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;1 for each bit compared, if all bits are 1; otherwise 0.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the columns are different lengths, the return values are treated as though they are all equal in length and are right-extended with zero bytes. For example, given a group containing hex values &lt;code&gt;ff&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, and &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;BIT_AND&lt;/code&gt; ignores the null value and extends the value &lt;code&gt;f&lt;/code&gt; to &lt;code&gt;f0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The example that follows uses table &lt;code&gt;t&lt;/code&gt; with a single column of &lt;code&gt;VARBINARY&lt;/code&gt; data type:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t ( c VARBINARY(2) );
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xFF00&amp;#39;));
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xFFFF&amp;#39;));
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xF00F&amp;#39;));
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query table &lt;code&gt;t&lt;/code&gt; to see column &lt;code&gt;c&lt;/code&gt; output:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_HEX(c) FROM t;
 TO_HEX
--------
 ff00
 ffff
 f00f
(3 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Query table &lt;code&gt;t&lt;/code&gt; to get the AND value for column &lt;code&gt;c&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_HEX(BIT_AND(c)) FROM t;
 TO_HEX
--------
 f000
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The function is applied pairwise to all values in the group, resulting in &lt;code&gt;f000&lt;/code&gt;, which is determined as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ff00&lt;/code&gt; (record 1) is compared with &lt;code&gt;ffff&lt;/code&gt; (record 2), which results in &lt;code&gt;ff00&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The result from the previous comparison is compared with &lt;code&gt;f00f&lt;/code&gt; (record 3), which results in &lt;code&gt;f000&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/sql-reference/data-types/binary-data-types-binary-and-varbinary/#&#34;&gt;Binary data types (BINARY and VARBINARY)&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BIT_OR</title>
      <link>/en/sql-reference/functions/aggregate-functions/bit-or/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/bit-or/</guid>
      <description>
        
        
        &lt;p&gt;Takes the bitwise OR of all non-null input values. If the input parameter is NULL, the return value is also 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;BIT_OR ( &lt;span class=&#34;code-variable&#34;&gt;expression&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 BINARY or VARBINARY input value to evaluate. BIT_OR operates on VARBINARY types explicitly and on BINARY types implicitly through &lt;a href=&#34;../../../../en/sql-reference/data-types/data-type-coercion-chart/&#34;&gt;casts&lt;/a&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;BIT_OR&lt;/code&gt; returns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The same value as the argument data type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;1 for each bit compared, if any bit is 1; otherwise 0.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the columns are different lengths, the return values are treated as though they are all equal in length and are right-extended with zero bytes. For example, given a group containing hex values &lt;code&gt;ff&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, and &lt;code&gt;f&lt;/code&gt;, the function ignores the null value and extends the value &lt;code&gt;f&lt;/code&gt; to &lt;code&gt;f0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The example that follows uses table &lt;code&gt;t&lt;/code&gt; with a single column of &lt;code&gt;VARBINARY&lt;/code&gt; data type:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t ( c VARBINARY(2) );
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xFF00&amp;#39;));
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xFFFF&amp;#39;));
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xF00F&amp;#39;));
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query table &lt;code&gt;t&lt;/code&gt; to see column &lt;code&gt;c&lt;/code&gt; output:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_HEX(c) FROM t;
 TO_HEX
--------
 ff00
 ffff
 f00f
(3 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Query table &lt;code&gt;t&lt;/code&gt; to get the OR value for column &lt;code&gt;c&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_HEX(BIT_OR(c)) FROM t;
 TO_HEX
--------
 ffff
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The function is applied pairwise to all values in the group, resulting in &lt;code&gt;ffff&lt;/code&gt;, which is determined as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ff00&lt;/code&gt; (record 1) is compared with &lt;code&gt;ffff&lt;/code&gt;, which results in &lt;code&gt;ffff&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;ff00&lt;/code&gt; result from the previous comparison is compared with &lt;code&gt;f00f&lt;/code&gt; (record 3), which results in &lt;code&gt;ffff&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;a href=&#34;../../../../en/sql-reference/data-types/binary-data-types-binary-and-varbinary/#&#34;&gt;Binary data types (BINARY and VARBINARY)&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BIT_XOR</title>
      <link>/en/sql-reference/functions/aggregate-functions/bit-xor/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/bit-xor/</guid>
      <description>
        
        
        &lt;p&gt;Takes the bitwise &lt;code&gt;XOR&lt;/code&gt; of all non-null input values. If the input parameter is &lt;code&gt;NULL&lt;/code&gt;, the return value is also &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;BIT_XOR ( &lt;span class=&#34;code-variable&#34;&gt;expression&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 &lt;code&gt;BINARY&lt;/code&gt; or &lt;code&gt;VARBINARY&lt;/code&gt; input value to evaluate. &lt;code&gt;BIT_XOR&lt;/code&gt; operates on &lt;code&gt;VARBINARY&lt;/code&gt; types explicitly and on &lt;code&gt;BINARY&lt;/code&gt; types implicitly through &lt;a href=&#34;../../../../en/sql-reference/data-types/data-type-coercion-chart/&#34;&gt;casts&lt;/a&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;BIT_XOR&lt;/code&gt; returns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The same value as the argument data type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;1 for each bit compared, if there are an odd number of arguments with set bits; otherwise 0.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the columns are different lengths, the return values are treated as though they are all equal in length and are right-extended with zero bytes. For example, given a group containing hex values &lt;code&gt;ff&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, and &lt;code&gt;f&lt;/code&gt;, the function ignores the null value and extends the value &lt;code&gt;f&lt;/code&gt; to &lt;code&gt;f0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;First create a sample table and projections with binary columns:&lt;/p&gt;
&lt;p&gt;The example that follows uses table &lt;code&gt;t&lt;/code&gt; with a single column of &lt;code&gt;VARBINARY&lt;/code&gt; data type:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t ( c VARBINARY(2) );
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xFF00&amp;#39;));
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xFFFF&amp;#39;));
=&amp;gt; INSERT INTO t values(HEX_TO_BINARY(&amp;#39;0xF00F&amp;#39;));
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query table &lt;code&gt;t&lt;/code&gt; to see column &lt;code&gt;c&lt;/code&gt; output:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_HEX(c) FROM t;
 TO_HEX
--------
 ff00
 ffff
 f00f
(3 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Query table &lt;code&gt;t&lt;/code&gt; to get the XOR value for column &lt;code&gt;c&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT TO_HEX(BIT_XOR(c)) FROM t;
 TO_HEX
--------
 f0f0
(1 row)
&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/data-types/binary-data-types-binary-and-varbinary/#&#34;&gt;Binary data types (BINARY and VARBINARY)&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: BOOL_AND [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/bool-and-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/bool-and-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Processes Boolean values and returns a Boolean value result. 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; (false).&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; )
&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 coerced to a Boolean data type.&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 to use aggregate functions &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;. The sample table &lt;code&gt;mixers&lt;/code&gt; includes columns for models and colors.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE mixers(model VARCHAR(20), colors VARCHAR(20));
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample data into the table. The sample adds two color fields for each model.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO mixers
SELECT &amp;#39;beginner&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;intermediate&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;intermediate&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;advanced&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;advanced&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;professional&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;professional&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;beginner&amp;#39;, &amp;#39;green&amp;#39;;
 OUTPUT
--------
      8
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query the table. The result shows models that have two blue (&lt;code&gt;BOOL_AND&lt;/code&gt;), one or two blue (&lt;code&gt;BOOL_OR&lt;/code&gt;), and specifically not more than one blue (&lt;code&gt;BOOL_XOR&lt;/code&gt;) mixer.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT model,
BOOL_AND(colors= &amp;#39;blue&amp;#39;)AS two_blue,
BOOL_OR(colors= &amp;#39;blue&amp;#39;)AS one_or_two_blue,
BOOL_XOR(colors= &amp;#39;blue&amp;#39;)AS specifically_not_more_than_one_blue
FROM mixers
GROUP BY model;

    model     | two_blue | one_or_two_blue | specifically_not_more_than_one_blue
--------------+----------+-----------------+-------------------------------------
 advanced     | f        | t               | t
 beginner     | f        | f               | f
 intermediate | t        | t               | f
 professional | f        | t               | t
(4 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/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/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/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/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 [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/bool-or-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/bool-or-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Processes Boolean values and returns a Boolean value result. 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; )
&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 coerced to a Boolean data type.&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 to use aggregate functions &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;. The sample table &lt;code&gt;mixers&lt;/code&gt; includes columns for models and colors.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE mixers(model VARCHAR(20), colors VARCHAR(20));
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample data into the table. The sample adds two color fields for each model.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO mixers
SELECT &amp;#39;beginner&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;intermediate&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;intermediate&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;advanced&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;advanced&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;professional&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;professional&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;beginner&amp;#39;, &amp;#39;green&amp;#39;;
 OUTPUT
--------
      8
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query the table. The result shows models that have two blue (&lt;code&gt;BOOL_AND&lt;/code&gt;), one or two blue (&lt;code&gt;BOOL_OR&lt;/code&gt;), and specifically not more than one blue (&lt;code&gt;BOOL_XOR&lt;/code&gt;) mixer.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT model,
BOOL_AND(colors= &amp;#39;blue&amp;#39;)AS two_blue,
BOOL_OR(colors= &amp;#39;blue&amp;#39;)AS one_or_two_blue,
BOOL_XOR(colors= &amp;#39;blue&amp;#39;)AS specifically_not_more_than_one_blue
FROM mixers
GROUP BY model;

    model     | two_blue | one_or_two_blue | specifically_not_more_than_one_blue
--------------+----------+-----------------+-------------------------------------
 advanced     | f        | t               | t
 beginner     | f        | f               | f
 intermediate | t        | t               | f
 professional | f        | t               | t
(4 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/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/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/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/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 [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/bool-xor-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/bool-xor-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Processes Boolean values and returns a Boolean value result. If specifically 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; )
&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 coerced to a Boolean data type.&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 to use aggregate functions &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;. The sample table &lt;code&gt;mixers&lt;/code&gt; includes columns for models and colors.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE mixers(model VARCHAR(20), colors VARCHAR(20));
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Insert sample data into the table. The sample adds two color fields for each model.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT INTO mixers
SELECT &amp;#39;beginner&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;intermediate&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;intermediate&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;advanced&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;advanced&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;professional&amp;#39;, &amp;#39;blue&amp;#39;
UNION ALL
SELECT &amp;#39;professional&amp;#39;, &amp;#39;green&amp;#39;
UNION ALL
SELECT &amp;#39;beginner&amp;#39;, &amp;#39;green&amp;#39;;
 OUTPUT
--------
      8
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Query the table. The result shows models that have two blue (&lt;code&gt;BOOL_AND&lt;/code&gt;), one or two blue (&lt;code&gt;BOOL_OR&lt;/code&gt;), and specifically not more than one blue (&lt;code&gt;BOOL_XOR&lt;/code&gt;) mixer.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT model,
BOOL_AND(colors= &amp;#39;blue&amp;#39;)AS two_blue,
BOOL_OR(colors= &amp;#39;blue&amp;#39;)AS one_or_two_blue,
BOOL_XOR(colors= &amp;#39;blue&amp;#39;)AS specifically_not_more_than_one_blue
FROM mixers
GROUP BY model;

    model     | two_blue | one_or_two_blue | specifically_not_more_than_one_blue
--------------+----------+-----------------+-------------------------------------
 advanced     | f        | t               | t
 beginner     | f        | f               | f
 intermediate | t        | t               | f
 professional | f        | t               | t
(4 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/bool-xor-analytic/#&#34;&gt;BOOL_XOR [analytic]&lt;/a&gt;
&lt;/li&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/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/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: CORR</title>
      <link>/en/sql-reference/functions/aggregate-functions/corr/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/corr/</guid>
      <description>
        
        
        &lt;p&gt;Returns the &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; coefficient of correlation of a set of expression pairs, as per the &lt;a href=&#34;https://en.wikipedia.org/wiki/Pearson_correlation_coefficient&#34;&gt;Pearson correlation coefficient&lt;/a&gt;. &lt;code&gt;CORR&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, the function returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CORR ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 CORR (Annual_salary, Employee_age) FROM employee_dimension;
         CORR
----------------------
 -0.00719153413192422
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: COUNT [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/count-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/count-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Returns as a BIGINT the number of rows in each group where the expression is not NULL. If the query has no GROUP BY clause, COUNT returns the number of table rows.&lt;/p&gt;
&lt;p&gt;The COUNT aggregate function differs from the &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/count-analytic/&#34;&gt;COUNT&lt;/a&gt; analytic function, which returns the number 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;.&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 ( [ * ] [ ALL | DISTINCT ] &lt;span class=&#34;code-variable&#34;&gt;expression&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;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies to count all rows in the specified table or each group.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;ALL | DISTINCT&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies how to count rows where &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; has a non-null value:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ALL&lt;/code&gt; (default): Counts all rows where &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; evaluates to a non-null value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;DISTINCT&lt;/code&gt;: Counts all rows where &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; evaluates to a distinct non-null value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The column or expression whose non-null values are counted.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query returns the number of distinct values in a column:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT COUNT (DISTINCT date_key) FROM date_dimension;

 COUNT
-------
  1826
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This example returns the number of distinct return values from an expression:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT COUNT (DISTINCT date_key + product_key) FROM inventory_fact;

 COUNT
-------
 21560
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can create an equivalent query using the &lt;span class=&#34;sql&#34;&gt;LIMIT&lt;/span&gt; keyword to restrict the number of rows returned:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT COUNT(date_key + product_key) FROM inventory_fact GROUP BY date_key LIMIT 10;

 COUNT
-------
   173
    31
   321
   113
   286
    84
   244
   238
   145
   202
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query uses &lt;span class=&#34;sql&#34;&gt;GROUP BY&lt;/span&gt; to count distinct values within groups:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT product_key, COUNT (DISTINCT date_key) FROM inventory_fact
   GROUP BY product_key LIMIT 10;

 product_key | count
-------------+-------
           1 |    12
           2 |    18
           3 |    13
           4 |    17
           5 |    11
           6 |    14
           7 |    13
           8 |    17
           9 |    15
          10 |    12
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query returns the number of distinct products and the total inventory within each date key:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT date_key, COUNT (DISTINCT product_key), SUM(qty_in_stock) FROM inventory_fact
   GROUP BY date_key LIMIT 10;

 date_key | count |  sum
----------+-------+--------
        1 |   173 |  88953
        2 |    31 |  16315
        3 |   318 | 156003
        4 |   113 |  53341
        5 |   285 | 148380
        6 |    84 |  42421
        7 |   241 | 119315
        8 |   238 | 122380
        9 |   142 |  70151
       10 |   202 |  95274
(10 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This query selects each distinct &lt;code&gt;product_key&lt;/code&gt; value and then counts the number of distinct &lt;code&gt;date_key&lt;/code&gt; values for all records with the specific &lt;code&gt;product_key&lt;/code&gt; value. It also counts the number of distinct &lt;code&gt;warehouse_key&lt;/code&gt; values in all records with the specific &lt;code&gt;product_key&lt;/code&gt; value:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT product_key, COUNT (DISTINCT date_key), COUNT (DISTINCT warehouse_key) FROM inventory_fact
   GROUP BY product_key LIMIT 15;

 product_key | count | count
-------------+-------+-------
           1 |    12 |    12
           2 |    18 |    18
           3 |    13 |    12
           4 |    17 |    18
           5 |    11 |     9
           6 |    14 |    13
           7 |    13 |    13
           8 |    17 |    15
           9 |    15 |    14
          10 |    12 |    12
          11 |    11 |    11
          12 |    13 |    12
          13 |     9 |     7
          14 |    13 |    13
          15 |    18 |    17
(15 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This query selects each distinct &lt;code&gt;product_key&lt;/code&gt; value, counts the number of distinct &lt;code&gt;date_key&lt;/code&gt; and &lt;code&gt;warehouse_key&lt;/code&gt; values for all records with the specific &lt;code&gt;product_key&lt;/code&gt; value, and then sums all &lt;code&gt;qty_in_stock&lt;/code&gt; values in records with the specific &lt;code&gt;product_key&lt;/code&gt; value. It then returns the number of &lt;code&gt;product_version&lt;/code&gt; values in records with the specific &lt;code&gt;product_key&lt;/code&gt; value:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT product_key, COUNT (DISTINCT date_key),
      COUNT (DISTINCT warehouse_key),
      SUM (qty_in_stock),
      COUNT (product_version)
      FROM inventory_fact GROUP BY product_key LIMIT 15;

 product_key | count | count |  sum  | count
-------------+-------+-------+-------+-------
           1 |    12 |    12 |  5530 |    12
           2 |    18 |    18 |  9605 |    18
           3 |    13 |    12 |  8404 |    13
           4 |    17 |    18 | 10006 |    18
           5 |    11 |     9 |  4794 |    11
           6 |    14 |    13 |  7359 |    14
           7 |    13 |    13 |  7828 |    13
           8 |    17 |    15 |  9074 |    17
           9 |    15 |    14 |  7032 |    15
          10 |    12 |    12 |  5359 |    12
          11 |    11 |    11 |  6049 |    11
          12 |    13 |    12 |  6075 |    13
          13 |     9 |     7 |  3470 |     9
          14 |    13 |    13 |  5125 |    13
          15 |    18 |    17 |  9277 |    18
(15 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/#&#34;&gt;Analytic functions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/avg-aggregate/#&#34;&gt;AVG [aggregate]&lt;/a&gt;
&lt;/li&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/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/approximate-count-distinct/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct-synopsis/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT_SYNOPSIS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/approximate-count-distinct-of-synopsis/#&#34;&gt;APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: COVAR_POP</title>
      <link>/en/sql-reference/functions/aggregate-functions/covar-pop/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/covar-pop/</guid>
      <description>
        
        
        &lt;p&gt;Returns the population covariance for a set of expression pairs. The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;COVAR_POP&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, the function returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT COVAR_POP ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 COVAR_POP (Annual_salary, Employee_age)
      FROM employee_dimension;
     COVAR_POP
-------------------
 -9032.34810730019
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: COVAR_SAMP</title>
      <link>/en/sql-reference/functions/aggregate-functions/covar-samp/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/covar-samp/</guid>
      <description>
        
        
        &lt;p&gt;Returns the sample covariance for a set of expression pairs. The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;COVAR_SAMP&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, the function returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT COVAR_SAMP ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 COVAR_SAMP (Annual_salary, Employee_age)
      FROM employee_dimension;
    COVAR_SAMP
-------------------
 -9033.25143244343
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: GROUP_ID</title>
      <link>/en/sql-reference/functions/aggregate-functions/group-id/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/group-id/</guid>
      <description>
        
        
        &lt;p&gt;Uniquely identifies duplicate sets for GROUP BY queries that return duplicate grouping sets. This function returns one or more integers, starting with zero (0), as identifiers.&lt;/p&gt;
&lt;p&gt;For the number of duplicates &lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt; for a particular grouping, GROUP_ID returns a range of sequential numbers, 0 to &lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt;–1. For the first each unique group it encounters, GROUP_ID returns the value 0. If GROUP_ID finds the same grouping again, the function returns 1, then returns 2 for the next found grouping, and so on.

&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;

Use &lt;code&gt;GROUP_ID&lt;/code&gt; only in &lt;code&gt;SELECT&lt;/code&gt; statements that contain a
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY&lt;/a&gt;&lt;/code&gt; aggregate:
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/cube-aggregate/#&#34;&gt;CUBE&lt;/a&gt;&lt;/code&gt;,
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS&lt;/a&gt;&lt;/code&gt;, and
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP&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;GROUP_ID ()
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;This example shows how GROUP_ID creates unique identifiers when a query produces duplicate groupings. For an expenses table, the following query groups the results by category of expense and year and rolls up the sum for those two columns. The results have duplicate groupings for category and NULL. The first grouping has a GROUP_ID of 0, and the second grouping has a GROUP_ID of 1.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT Category, Year, SUM(Amount), GROUPING_ID(Category, Year),
   GROUP_ID() FROM expenses GROUP BY Category, ROLLUP(Category,Year)
   ORDER BY Category, Year, GROUPING_ID();
  Category   | Year |  SUM   | GROUPING_ID | GROUP_ID
-------------+------+--------+-------------+----------
 Books       | 2005 |  39.98 |           0 |        0
 Books       | 2007 |  29.99 |           0 |        0
 Books       | 2008 |  29.99 |           0 |        0
 Books       |      |  99.96 |           1 |        0
 Books       |      |  99.96 |           1 |        1
 Electricity | 2005 | 109.99 |           0 |        0
 Electricity | 2006 | 109.99 |           0 |        0
 Electricity | 2007 | 229.98 |           0 |        0
 Electricity |      | 449.96 |           1 |        1
 Electricity |      | 449.96 |           1 |        0
&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/group-by-clause/cube-aggregate/#&#34;&gt;CUBE aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping/#&#34;&gt;GROUPING&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping-id/#&#34;&gt;GROUPING_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: GROUPING</title>
      <link>/en/sql-reference/functions/aggregate-functions/grouping/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/grouping/</guid>
      <description>
        
        
        &lt;p&gt;Disambiguates the use of &lt;code&gt;NULL&lt;/code&gt; values when &lt;code&gt;GROUP BY&lt;/code&gt; queries with multilevel aggregates generate NULL values to identify subtotals in grouping columns. Such &lt;code&gt;NULL&lt;/code&gt; values from the original data can also occur in rows. &lt;code&gt;GROUPING&lt;/code&gt; returns 1, if the value of &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt; is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;NULL&lt;/code&gt;, representing an aggregated value&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;0 for any other value, including &lt;code&gt;NULL&lt;/code&gt; values in rows&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;

Use &lt;code&gt;GROUPING&lt;/code&gt; only in &lt;code&gt;SELECT&lt;/code&gt; statements that contain a
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY&lt;/a&gt;&lt;/code&gt; aggregate:
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/cube-aggregate/#&#34;&gt;CUBE&lt;/a&gt;&lt;/code&gt;,
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS&lt;/a&gt;&lt;/code&gt;, and
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP&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;GROUPING ( &lt;span class=&#34;code-variable&#34;&gt;expression&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;An expression in the &lt;code&gt;GROUP BY&lt;/code&gt; clause&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query uses the &lt;code&gt;GROUPING&lt;/code&gt; function, taking one of the &lt;code&gt;GROUP BY&lt;/code&gt; expressions as an argument. For each row, &lt;code&gt;GROUPING&lt;/code&gt; returns one of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;0&lt;/code&gt;: The column is part of the group for that row&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;1&lt;/code&gt;: The column is not part of the group for that row&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The 1 in the &lt;code&gt;GROUPING(Year)&lt;/code&gt; column for electricity and books indicates that these values are subtotals. The right-most column values for both &lt;code&gt;GROUPING(Category)&lt;/code&gt; and &lt;code&gt;GROUPING(Year)&lt;/code&gt; are &lt;code&gt;1&lt;/code&gt;. This value indicates that neither column contributed to the &lt;code&gt;GROUP BY&lt;/code&gt;. The final row represents the total sales.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT Category, Year, SUM(Amount),
   GROUPING(Category), GROUPING(Year) FROM expenses
   GROUP BY ROLLUP(Category, Year) ORDER BY Category, Year, GROUPING_ID();
   Category  | Year |  SUM   | GROUPING | GROUPING
-------------+------+--------+----------+----------
 Books       | 2005 |  39.98 |        0 |        0
 Books       | 2007 |  29.99 |        0 |        0
 Books       | 2008 |  29.99 |        0 |        0
 Books       |      |  99.96 |        0 |        1
 Electricity | 2005 | 109.99 |        0 |        0
 Electricity | 2006 | 109.99 |        0 |        0
 Electricity | 2007 | 229.98 |        0 |        0
 Electricity |      | 449.96 |        0 |        1
             |      | 549.92 |        1 |        1
&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/group-by-clause/cube-aggregate/#&#34;&gt;CUBE aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/group-id/#&#34;&gt;GROUP_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping-id/#&#34;&gt;GROUPING_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: GROUPING_ID</title>
      <link>/en/sql-reference/functions/aggregate-functions/grouping-id/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/grouping-id/</guid>
      <description>
        
        
        &lt;p&gt;Concatenates the set of Boolean values generated by the&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping/&#34;&gt; GROUPING&lt;/a&gt; function into a bit vector. &lt;code&gt;GROUPING_ID&lt;/code&gt; treats the bit vector as a binary number and returns it as a base-10 value that identifies the grouping set combination.&lt;/p&gt;
&lt;p&gt;By using &lt;code&gt;GROUPING_ID&lt;/code&gt; you avoid the need for multiple, individual GROUPING functions. &lt;code&gt;GROUPING_ID&lt;/code&gt; simplifies row-filtering conditions, because rows of interest are identified using a single return from &lt;code&gt;GROUPING_ID = &lt;/code&gt;&lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt;. Use &lt;code&gt;GROUPING_ID&lt;/code&gt; to identify grouping combinations.

&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;

Use &lt;code&gt;GROUPING_ID&lt;/code&gt; only in &lt;code&gt;SELECT&lt;/code&gt; statements that contain a
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY&lt;/a&gt;&lt;/code&gt; aggregate:
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/cube-aggregate/#&#34;&gt;CUBE&lt;/a&gt;&lt;/code&gt;,
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS&lt;/a&gt;&lt;/code&gt;, and
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP&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;GROUPING_ID ( [&lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;[,...] )
&lt;/code&gt;&lt;/pre&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;An expression that matches one of the expressions in the &lt;code&gt;GROUP BY&lt;/code&gt; clause.
&lt;p&gt;If the &lt;code&gt;GROUP BY&lt;/code&gt; clause includes a list of expressions, &lt;code&gt;GROUPING_ID&lt;/code&gt; returns a number corresponding to the &lt;code&gt;GROUPING&lt;/code&gt; bit vector associated with a row.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;This example shows how calling &lt;code&gt;GROUPING_ID&lt;/code&gt; without an expression returns the GROUPING bit vector associated with a full set of multilevel aggregate expressions. The &lt;code&gt;GROUPING_ID&lt;/code&gt; value is comparable to &lt;code&gt;GROUPING_ID(a,b)&lt;/code&gt; because &lt;code&gt;GROUPING_ID()&lt;/code&gt; includes all columns in the &lt;code&gt;GROUP BY ROLLUP&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT a,b,COUNT(*), GROUPING_ID() FROM T GROUP BY ROLLUP(a,b);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the following query, the &lt;code&gt;GROUPING(Category)&lt;/code&gt; and &lt;code&gt;GROUPING(Year)&lt;/code&gt; columns have three combinations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;0,0&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;0,1&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;1,1&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT Category, Year, SUM(Amount),
   GROUPING(Category), GROUPING(Year) FROM expenses
   GROUP BY ROLLUP(Category, Year) ORDER BY Category, Year, GROUPING_ID();
  Category   | Year |  SUM   | GROUPING | GROUPING
-------------+------+--------+----------+----------
 Books       | 2005 |  39.98 |        0 |        0
 Books       | 2007 |  29.99 |        0 |        0
 Books       | 2008 |  29.99 |        0 |        0
 Books       |      |  99.96 |        0 |        1
 Electricity | 2005 | 109.99 |        0 |        0
 Electricity | 2006 | 109.99 |        0 |        0
 Electricity | 2007 | 229.98 |        0 |        0
 Electricity |      | 449.96 |        0 |        1
             |      | 549.92 |        1 |        1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;GROUPING_ID&lt;/code&gt; converts these values as follows:

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;th &gt;
&lt;strong&gt;Binary Set Values&lt;/strong&gt;&lt;/th&gt; 

&lt;th &gt;
&lt;strong&gt;Decimal Equivalents&lt;/strong&gt;&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
00&lt;/td&gt; 

&lt;td &gt;
0&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
01&lt;/td&gt; 

&lt;td &gt;
1&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
11&lt;/td&gt; 

&lt;td &gt;
3&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
0&lt;/td&gt; 

&lt;td &gt;
Category, Year&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;The following query returns the single number for each &lt;code&gt;GROUP BY&lt;/code&gt; level that appears in the gr_id column:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT Category, Year, SUM(Amount),
   GROUPING(Category),GROUPING(Year),GROUPING_ID(Category,Year) AS gr_id
   FROM expenses GROUP BY ROLLUP(Category, Year);
  Category   | Year |  SUM   | GROUPING | GROUPING | gr_id
-------------+------+--------+----------+----------+-------
 Books       | 2008 |  29.99 |        0 |        0 |     0
 Books       | 2005 |  39.98 |        0 |        0 |     0
 Electricity | 2007 | 229.98 |        0 |        0 |     0
 Books       | 2007 |  29.99 |        0 |        0 |     0
 Electricity | 2005 | 109.99 |        0 |        0 |     0
 Electricity |      | 449.96 |        0 |        1 |     1
             |      | 549.92 |        1 |        1 |     3
 Electricity | 2006 | 109.99 |        0 |        0 |     0
 Books       |      |  99.96 |        0 |        1 |     1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;gr_id&lt;/code&gt; value determines the &lt;code&gt;GROUP BY&lt;/code&gt; level for each row:&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;GROUP BY Level&lt;/dt&gt;
&lt;dd&gt;GROUP BY Row Level&lt;/dd&gt;
&lt;dt&gt;3&lt;/dt&gt;
&lt;dd&gt;Total sum&lt;/dd&gt;
&lt;dt&gt;1&lt;/dt&gt;
&lt;dd&gt;Category&lt;/dd&gt;
&lt;dt&gt;0&lt;/dt&gt;
&lt;dd&gt;Category, year&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;You can also use the &lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/string-functions/decode/#&#34;&gt;DECODE&lt;/a&gt; function to give the values more meaning by comparing each search value individually:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT Category, Year, SUM(AMOUNT), DECODE(GROUPING_ID(Category, Year),
       3, &amp;#39;Total&amp;#39;,
       1, &amp;#39;Category&amp;#39;,
       0, &amp;#39;Category,Year&amp;#39;)
   AS GROUP_NAME FROM expenses GROUP BY ROLLUP(Category, Year);
  Category   | Year |  SUM   |  GROUP_NAME
-------------+------+--------+---------------
 Electricity | 2006 | 109.99 | Category,Year
 Books       |      |  99.96 | Category
 Electricity | 2007 | 229.98 | Category,Year
 Books       | 2007 |  29.99 | Category,Year
 Electricity | 2005 | 109.99 | Category,Year
 Electricity |      | 449.96 | Category
             |      | 549.92 | Total
 Books       | 2005 |  39.98 | Category,Year
 Books       | 2008 |  29.99 | Category,Year
&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/group-by-clause/cube-aggregate/#&#34;&gt;CUBE aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/group-id/#&#34;&gt;GROUP_ID&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/grouping/#&#34;&gt;GROUPING&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/grouping-sets-aggregate/#&#34;&gt;GROUPING SETS aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/#&#34;&gt;GROUP BY clause&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/statements/select/group-by-clause/rollup-aggregate/#&#34;&gt;ROLLUP aggregate&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: LISTAGG</title>
      <link>/en/sql-reference/functions/aggregate-functions/listagg/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/listagg/</guid>
      <description>
        
        
        &lt;p&gt;Transforms non-null values from a group of rows into a list of values that are delimited by commas (default) or a configurable separator. LISTAGG can be used to denormalize rows into a string of concatenated values.&lt;/p&gt;
&lt;h2 id=&#34;behavior-type&#34;&gt;Behavior type&lt;/h2&gt;
&lt;p&gt;&lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/immutable-invariant-functions/&#34; title=&#34;&#34;&gt;Immutable&lt;/a&gt; if the WITHIN GROUP ORDER BY clause specifies a column or set of columns that resolves to unique values within the aggregated list; otherwise &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/volatile-functions/&#34; title=&#34;&#34;&gt;Volatile&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;LISTAGG ( &lt;span class=&#34;code-variable&#34;&gt;aggregate-expression&lt;/span&gt; [ USING PARAMETERS &lt;span class=&#34;code-variable&#34;&gt;parameter&lt;/span&gt;=&lt;span class=&#34;code-variable&#34;&gt;value&lt;/span&gt;][,...] ] ) [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/#&#34;&gt;within-group-order-by-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;aggregate-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Aggregation of one or more columns or column expressions to select from the source table or view.
&lt;p&gt;LISTAGG does not support &lt;a href=&#34;../../../../en/sql-reference/data-types/spatial-data-types/&#34;&gt;spatial data types&lt;/a&gt; directly. In order to pass column data of this type, convert the data to strings with the geospatial function &lt;a href=&#34;../../../../en/sql-reference/functions/geospatial-functions/st-astext/#&#34;&gt;ST_AsText&lt;/a&gt;.

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

Converted spatial data frequently contains commas. LISTAGG uses comma as the default separator character. To avoid ambiguous output, override this default by setting the function&#39;s &lt;code&gt;separator&lt;/code&gt; parameter to another character.

&lt;/div&gt;&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;span class=&#34;code-variable&#34;&gt;[within-group-order-by-clause](/en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/)&lt;/span&gt;&lt;/dt&gt;
&lt;dd&gt;Sorts aggregated values within each group of rows, where &lt;em&gt;&lt;code&gt;column-expression&lt;/code&gt;&lt;/em&gt; is typically a column in &lt;em&gt;&lt;code&gt;aggregate-expression&lt;/code&gt;&lt;/em&gt;:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITHIN GROUP (ORDER BY { &lt;span class=&#34;code-variable&#34;&gt;column-expression&lt;/span&gt;[ &lt;span class=&#34;code-variable&#34;&gt;sort-qualifiers&lt;/span&gt; ] }[,...])
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;&lt;code&gt;sort-qualifiers&lt;/code&gt;&lt;/em&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;   { ASC | DESC [ NULLS { FIRST | LAST | AUTO } ] }
&lt;/code&gt;&lt;/pre&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;

WITHIN GROUP ORDER BY can consume a large amount of memory per group. Including wide strings in the aggregate expression can also adversely affect performance. To minimize memory consumption, create projections that support &lt;a href=&#34;../../../../en/data-analysis/query-optimization/group-by-queries/group-by-implementation-options/#GROUPBY&#34;&gt;GROUPBY PIPELINED&lt;/a&gt;.

&lt;/div&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;th &gt;
Parameter name&lt;/th&gt; 

&lt;th &gt;
Set to...&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
&lt;code&gt;max_length&lt;/code&gt;&lt;/td&gt; 

&lt;td &gt;




&lt;p&gt;An integer or integer expression that specifies in bytes the maximum length of the result, up to 32M.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default:&lt;/strong&gt; 1024&lt;/p&gt;
&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
&lt;code&gt;separator&lt;/code&gt;&lt;/td&gt; 

&lt;td &gt;




&lt;p&gt;Separator string of length 0 to 80, inclusive. A length of 0 concatenates the output with no separators.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default:&lt;/strong&gt; comma (&lt;code&gt;,&lt;/code&gt;)&lt;/p&gt;
&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
&lt;code&gt;on_overflow&lt;/code&gt;&lt;/td&gt; 

&lt;td &gt;






&lt;p&gt;Specifies behavior when the result overflows the &lt;code&gt;max_length&lt;/code&gt; setting, one of the following strings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ERROR&lt;/code&gt; (default): Return an error when overflow occurs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;TRUNCATE&lt;/code&gt;: Remove any characters that exceed &lt;code&gt;max_length&lt;/code&gt; setting from the query result, and return the truncated string.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;h2 id=&#34;privileges&#34;&gt;Privileges&lt;/h2&gt;
&lt;p&gt;None&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;In the following query, the aggregated results in the &lt;code&gt;CityStat&lt;/code&gt;e column use the string &amp;quot; | &amp;quot; as a separator. The outer GROUP BY clause groups the output rows according to their &lt;code&gt;Region&lt;/code&gt; values. Within each group, the aggregated list items are sorted according to their &lt;code&gt;city&lt;/code&gt; values, as per the WITHIN GROUP ORDER BY clause:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \x
Expanded display is on.
=&amp;gt; WITH cd AS (SELECT DISTINCT (customer_city) city, customer_state, customer_region FROM customer_dimension)
SELECT customer_region Region, LISTAGG(city||&amp;#39;, &amp;#39;||customer_state USING PARAMETERS separator=&amp;#39; | &amp;#39;)
   WITHIN GROUP (ORDER BY city) CityAndState FROM cd GROUP BY region ORDER BY region;
-[ RECORD 1 ]+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Region       | East
CityAndState | Alexandria, VA | Allentown, PA | Baltimore, MD | Boston, MA | Cambridge, MA | Charlotte, NC | Clarksville, TN | Columbia, SC | Elizabeth, NJ | Erie, PA | Fayetteville, NC | Hartford, CT | Lowell, MA | Manchester, NH | Memphis, TN | Nashville, TN | New Haven, CT | New York, NY | Philadelphia, PA | Portsmouth, VA | Stamford, CT | Sterling Heights, MI | Washington, DC | Waterbury, CT
-[ RECORD 2 ]+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Region       | MidWest
CityAndState | Ann Arbor, MI | Cedar Rapids, IA | Chicago, IL | Columbus, OH | Detroit, MI | Evansville, IN | Flint, MI | Gary, IN | Green Bay, WI | Indianapolis, IN | Joliet, IL | Lansing, MI | Livonia, MI | Milwaukee, WI | Naperville, IL | Peoria, IL | Sioux Falls, SD | South Bend, IN | Springfield, IL
-[ RECORD 3 ]+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Region       | NorthWest
CityAndState | Bellevue, WA | Portland, OR | Seattle, WA
-[ RECORD 4 ]+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Region       | South
CityAndState | Abilene, TX | Athens, GA | Austin, TX | Beaumont, TX | Cape Coral, FL | Carrollton, TX | Clearwater, FL | Coral Springs, FL | Dallas, TX | El Paso, TX | Fort Worth, TX | Grand Prairie, TX | Houston, TX | Independence, MS | Jacksonville, FL | Lafayette, LA | McAllen, TX | Mesquite, TX | San Antonio, TX | Savannah, GA | Waco, TX | Wichita Falls, TX
-[ RECORD 5 ]+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Region       | SouthWest
CityAndState | Arvada, CO | Denver, CO | Fort Collins, CO | Gilbert, AZ | Las Vegas, NV | North Las Vegas, NV | Peoria, AZ | Phoenix, AZ | Pueblo, CO | Topeka, KS | Westminster, CO
-[ RECORD 6 ]+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Region       | West
CityAndState | Berkeley, CA | Burbank, CA | Concord, CA | Corona, CA | Costa Mesa, CA | Daly City, CA | Downey, CA | El Monte, CA | Escondido, CA | Fontana, CA | Fullerton, CA | Inglewood, CA | Lancaster, CA | Los Angeles, CA | Norwalk, CA | Orange, CA | Palmdale, CA | Pasadena, CA | Provo, UT | Rancho Cucamonga, CA | San Diego, CA | San Francisco, CA | San Jose, CA | Santa Clara, CA | Simi Valley, CA | Sunnyvale, CA | Thousand Oaks, CA | Vallejo, CA | Ventura, CA | West Covina, CA | West Valley City, UT
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MAX [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/max-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/max-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Returns the greatest value of an expression over a group of rows. The return value has the same type as the expression data type.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/max-analytic/&#34;&gt;&lt;code&gt;MAX&lt;/code&gt; analytic function&lt;/a&gt; function differs from the aggregate function, in that it returns the maximum value 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;.&lt;/p&gt;
&lt;p&gt;Aggregate functions &lt;code&gt;MIN&lt;/code&gt; and &lt;code&gt;MAX&lt;/code&gt; can operate with Boolean values. &lt;code&gt;MAX&lt;/code&gt; can act 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. 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, &lt;code&gt;MIN&lt;/code&gt; 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; )
&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;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query returns the largest value in column &lt;code&gt;sales_dollar_amount&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT MAX(sales_dollar_amount) AS highest_sale FROM store.store_sales_fact;
 highest_sale
--------------
          600
(1 row)
&lt;/code&gt;&lt;/pre&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; aggregate functions when you use them with a Boolean value. The sample creates a table, 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;=&amp;gt; CREATE TABLE min_max_functions (torf BOOL);

=&amp;gt; INSERT INTO min_max_functions VALUES (1);
=&amp;gt; INSERT INTO min_max_functions VALUES (0);

=&amp;gt; SELECT * FROM min_max_functions;
  torf
------
 t
 f
(2 rows)

=&amp;gt; SELECT min(torf) FROM min_max_functions;
 min
-----
 f
(1 row)

=&amp;gt; SELECT max(torf) FROM min_max_functions;
 max
-----
 t
(1 row)
&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/data-aggregation/#&#34;&gt;Data aggregation&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: MIN [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/min-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/min-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Returns the smallest value of an expression over a group of rows. The return value has the same type as the expression data type.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;MIN&lt;/code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/min-analytic/&#34;&gt; analytic function&lt;/a&gt; differs from the aggregate function, in that it returns the minimum value 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;.&lt;/p&gt;
&lt;p&gt;Aggregate functions &lt;code&gt;MIN&lt;/code&gt; and &lt;code&gt;MAX&lt;/code&gt; can operate with Boolean values. &lt;code&gt;MAX&lt;/code&gt; can act 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. 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, &lt;code&gt;MIN&lt;/code&gt; 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; )
&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;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following query returns the lowest salary from the &lt;code&gt;employee&lt;/code&gt; dimension table.&lt;/p&gt;
&lt;p&gt;This example shows how you can query to return the lowest salary from the &lt;code&gt;employee&lt;/code&gt; dimension table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT MIN(annual_salary) AS lowest_paid FROM employee_dimension;
 lowest_paid
-------------
        1200
(1 row)
&lt;/code&gt;&lt;/pre&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; aggregate functions when you use them with a Boolean value. The sample creates a table, 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;=&amp;gt; CREATE TABLE min_max_functions (torf BOOL);

=&amp;gt; INSERT INTO min_max_functions VALUES (1);
=&amp;gt; INSERT INTO min_max_functions VALUES (0);

=&amp;gt; SELECT * FROM min_max_functions;
  torf
------
 t
 f
(2 rows)

=&amp;gt; SELECT min(torf) FROM min_max_functions;
 min
-----
 f
(1 row)

=&amp;gt; SELECT max(torf) FROM min_max_functions;
 max
-----
 t
(1 row)
&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/data-aggregation/#&#34;&gt;Data aggregation&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_AVGX</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-avgx/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-avgx/</guid>
      <description>
        
        
        &lt;p&gt;Returns the &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; average of the independent expression in an expression pair. &lt;code&gt;REGR_AVGX&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_AVGX&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_AVGX ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_AVGX (Annual_salary, Employee_age)
      FROM employee_dimension;
 REGR_AVGX
-----------
    39.321
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_AVGY</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-avgy/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-avgy/</guid>
      <description>
        
        
        &lt;p&gt;Returns the &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; average of the dependent expression in an expression pair. The function eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, the function returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;REGR_AVGY ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_AVGY (Annual_salary, Employee_age)
      FROM employee_dimension;
 REGR_AVGY
------------
 58354.4913
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_COUNT</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-count/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-count/</guid>
      <description>
        
        
        &lt;p&gt;Returns the count of all rows in an expression pair. The function eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, the function returns &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_COUNT ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_COUNT (Annual_salary, Employee_age) FROM employee_dimension;
 REGR_COUNT
------------
      10000
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_INTERCEPT</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-intercept/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-intercept/</guid>
      <description>
        
        
        &lt;p&gt;Returns the y-intercept of the regression line determined by a set of expression pairs. The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;REGR_INTERCEPT&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_INTERCEPT&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_INTERCEPT ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_INTERCEPT (Annual_salary, Employee_age) FROM employee_dimension;
  REGR_INTERCEPT
------------------
 59929.5490163437
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_R2</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-r2/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-r2/</guid>
      <description>
        
        
        &lt;p&gt;Returns the square of the correlation coefficient of a set of expression pairs. The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;REGR_R2&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_R2&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_R2 ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_R2 (Annual_salary, Employee_age) FROM employee_dimension;
       REGR_R2
----------------------
 5.17181631706311e-05
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_SLOPE</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-slope/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-slope/</guid>
      <description>
        
        
        &lt;p&gt;Returns the slope of the regression line, determined by a set of expression pairs. The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;REGR_SLOPE&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_SLOPE&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_SLOPE ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_SLOPE (Annual_salary, Employee_age) FROM employee_dimension;
    REGR_SLOPE
------------------
 -40.056400303749
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_SXX</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-sxx/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-sxx/</guid>
      <description>
        
        
        &lt;p&gt;Returns the sum of squares of the difference between the independent expression (&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;) and its average.&lt;/p&gt;
&lt;p&gt;That is, REGR_SXX returns: ∑[(&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt; - average(&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;)(&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt; - average(&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;)]&lt;/p&gt;
&lt;p&gt;The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;REGR_SXX&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_SXX&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_SXX ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_SXX (Annual_salary, Employee_age) FROM employee_dimension;
  REGR_SXX
------------
 2254907.59
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_SXY</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-sxy/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-sxy/</guid>
      <description>
        
        
        &lt;p&gt;Returns the sum of products of the difference between the dependent expression (&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt;) and its average and the difference between the independent expression (&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;) and its average.&lt;/p&gt;
&lt;p&gt;That is, REGR_SXY returns: ∑[(&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt; - average(&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt;)(&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt; - average(&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;))]&lt;/p&gt;
&lt;p&gt;The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;REGR_SXY&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_SXY&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_SXY ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_SXY (Annual_salary, Employee_age) FROM employee_dimension;
     REGR_SXY
-------------------
 -90323481.0730019
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: REGR_SYY</title>
      <link>/en/sql-reference/functions/aggregate-functions/regr-syy/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/regr-syy/</guid>
      <description>
        
        
        &lt;p&gt;Returns the sum of squares of the difference between the dependent expression (&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt;) and its average.&lt;/p&gt;
&lt;p&gt;That is, REGR_SYY returns: ∑[(&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt; - average(&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt;)(&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt; - average(&lt;em&gt;&lt;code&gt;expression1&lt;/code&gt;&lt;/em&gt;)]&lt;/p&gt;
&lt;p&gt;The return value is of type &lt;code&gt;DOUBLE PRECISION&lt;/code&gt;. &lt;code&gt;REGR_SYY&lt;/code&gt; eliminates expression pairs where either expression in the pair is &lt;code&gt;NULL&lt;/code&gt;. If no rows remain, &lt;code&gt;REGR_SYY&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT REGR_SYY ( &lt;span class=&#34;code-variable&#34;&gt;expression1&lt;/span&gt;, &lt;span class=&#34;code-variable&#34;&gt;expression2&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;expression1&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The dependent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;dt&gt;&lt;em&gt;&lt;code&gt;expression2&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;The independent &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; expression&lt;/dd&gt;
&lt;/dl&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 REGR_SYY (Annual_salary, Employee_age) FROM employee_dimension;
     REGR_SYY
------------------
 69956728794707.2
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: STDDEV [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/stddev-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/stddev-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Evaluates the statistical sample standard deviation for each member of the group. The return value is the same as the square root of 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-samp-aggregate/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt;:&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;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; )
&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. &lt;code&gt;STDDEV&lt;/code&gt; returns the same data type as &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;related-functions&#34;&gt;Related functions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;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/aggregate-functions/stddev-samp-aggregate/#&#34;&gt;STDDEV_SAMP&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This aggregate function differs from analytic function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/stddev-analytic/#&#34;&gt;STDDEV&lt;/a&gt;&lt;/code&gt;, which computes the statistical sample standard deviation of the current row with respect to the 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;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/dense-rank-analytic/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;, &lt;code&gt;STDDEV&lt;/code&gt; 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 returns the statistical sample standard deviation for each household ID from the &lt;code&gt;customer_dimension&lt;/code&gt; table of the VMart example database:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT STDDEV(household_id) FROM customer_dimension;
   STDDEV
-----------------
 8651.5084240071
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: STDDEV_POP [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/stddev-pop-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/stddev-pop-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Evaluates the statistical population standard deviation for each member of the group.&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; )
&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. &lt;code&gt;STDDEV_POP&lt;/code&gt; returns the same data type as &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;related-functions&#34;&gt;Related functions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;This function differs from the analytic function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/stddev-pop-analytic/#&#34;&gt;STDDEV_POP&lt;/a&gt;&lt;/code&gt;, which evaluates the statistical population standard deviation for each member of the 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;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;STDDEV_POP&lt;/code&gt; returns the same value as the square root of 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-pop-aggregate/#&#34;&gt;VAR_POP&lt;/a&gt;&lt;/code&gt;:&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;/li&gt;
&lt;li&gt;
&lt;p&gt;When 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-samp-aggregate/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;, this function 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 returns the statistical population standard deviation for each household ID in the &lt;code&gt;customer&lt;/code&gt; table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT STDDEV_POP(household_id) FROM customer_dimension;
   STDDEV_POP
------------------
 8651.41895973367
(1 row)
&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/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 [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/stddev-samp-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/stddev-samp-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Evaluates the statistical sample standard deviation for each member of the group. The return value is the same as the square root of 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/var-samp-aggregate/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt;:&lt;/p&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;) = SQRT(VAR_SAMP(&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;STDDEV_SAMP ( &lt;span class=&#34;code-variable&#34;&gt;expression&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. &lt;code&gt;STDDEV_SAMP&lt;/code&gt; returns the same data type as &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;related-functions&#34;&gt;Related functions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;STDDEV_SAMP&lt;/code&gt; is semantically identical to nonstandard function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/stddev-aggregate/#&#34;&gt;STDDEV&lt;/a&gt;&lt;/code&gt;, which is provided for compatibility with other databases.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This aggregate function differs from analytic function 
&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;, which computes the statistical sample standard deviation of the current row with respect to the 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;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/dense-rank-analytic/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;, &lt;code&gt;STDDEV_SAMP&lt;/code&gt; 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 returns the statistical sample standard deviation for each household ID from the &lt;code&gt;customer&lt;/code&gt; dimension table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT STDDEV_SAMP(household_id) FROM customer_dimension;
   stddev_samp
------------------
 8651.50842400771
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: SUM [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/sum-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/sum-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Computes the sum of an expression over a group of rows. &lt;code&gt;SUM&lt;/code&gt; 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;p&gt;The &lt;code&gt;SUM&lt;/code&gt; aggregate function differs from the 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/sum-analytic/#&#34;&gt;SUM&lt;/a&gt;&lt;/code&gt; analytic function, which 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;.&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 ( [ ALL | DISTINCT ] &lt;span class=&#34;code-variable&#34;&gt;expression&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;ALL&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Invokes the aggregate function for all rows in the group (default)&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;DISTINCT&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Invokes the aggregate function for all distinct non-null values of the expression found in the group&lt;/dd&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;/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 the 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 total sum of the &lt;code&gt;product_cost&lt;/code&gt; column.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT SUM(product_cost) AS cost FROM product_dimension;
   cost
---------
 9042850
(1 row)
&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/avg-aggregate/#&#34;&gt;AVG [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/count-aggregate/#&#34;&gt;COUNT [aggregate]&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: SUM_FLOAT [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/sum-float-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/sum-float-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Computes the sum of an expression over a group of rows and returns a &lt;code&gt;DOUBLE PRECISION&lt;/code&gt; value.&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_FLOAT ( [ ALL | DISTINCT ] &lt;span class=&#34;code-variable&#34;&gt;expression&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;ALL&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Invokes the aggregate function for all rows in the group (default).&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;DISTINCT&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Invokes the aggregate function for all distinct non-null values of the expression found in the group.&lt;/dd&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 whose result is type &lt;code&gt;DOUBLE PRECISION&lt;/code&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 returns the floating-point sum of the average price from the product table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT SUM_FLOAT(average_competitor_price) AS cost FROM product_dimension;
   cost
----------
 18181102
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: TS_FIRST_VALUE</title>
      <link>/en/sql-reference/functions/aggregate-functions/ts-first-value/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/ts-first-value/</guid>
      <description>
        
        
        &lt;p&gt;Processes the data that belongs to each time slice. A time series aggregate (TSA) function, &lt;code&gt;TS_FIRST_VALUE&lt;/code&gt; returns the value at the start of the time slice, where an interpolation scheme is applied if the timeslice is missing, in which case the value is determined by the values corresponding to the previous (and next) timeslices based on the interpolation scheme of const (linear).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TS_FIRST_VALUE&lt;/code&gt; returns one output row per time slice, or one output row per partition per time slice if partition expressions are specified&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;TS_FIRST_VALUE ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ IGNORE NULLS ] [, { &amp;#39;CONST&amp;#39; | &amp;#39;LINEAR&amp;#39; } ] )
&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;An &lt;code&gt;INTEGER&lt;/code&gt; or &lt;code&gt;FLOAT&lt;/code&gt; expression on which to aggregate and interpolate.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;IGNORE NULLS&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;The &lt;code&gt;IGNORE NULLS&lt;/code&gt; behavior changes depending on a &lt;code&gt;CONST&lt;/code&gt; or &lt;code&gt;LINEAR&lt;/code&gt; interpolation scheme. 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; in Analyzing Data for details.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;&#39;CONST&#39; | &#39;LINEAR&#39;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the interpolation value as constant or linear:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;CONST&lt;/code&gt; (default): New value is interpolated based on previous input records.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;LINEAR&lt;/code&gt;: Values are interpolated in a linear slope based on the specified time slice.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;You must use an &lt;code&gt;ORDER BY&lt;/code&gt; clause with a &lt;code&gt;TIMESTAMP&lt;/code&gt; column.&lt;/p&gt;
&lt;h2 id=&#34;multiple-time-series-aggregate-functions&#34;&gt;Multiple time series aggregate functions&lt;/h2&gt;
&lt;p&gt;The same query can call multiple time series aggregate functions. They share the same gap-filling policy as defined by the &lt;a href=&#34;../../../../en/sql-reference/statements/select/timeseries-clause/#&#34;&gt;TIMESERIES clause&lt;/a&gt;; however, each time series aggregate function can specify its own interpolation policy. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol,
TS_FIRST_VALUE(bid, &amp;#39;const&amp;#39;) fv_c,
       TS_FIRST_VALUE(bid, &amp;#39;linear&amp;#39;) fv_l,
       TS_LAST_VALUE(bid, &amp;#39;const&amp;#39;) lv_c
FROM TickStore
TIMESERIES slice_time AS &amp;#39;3 seconds&amp;#39;
OVER(PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/&#34;&gt;Gap Filling and Interpolation&lt;/a&gt; in Analyzing Data.&lt;/p&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/ts-last-value/#&#34;&gt;TS_LAST_VALUE&lt;/a&gt;&lt;/code&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;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: TS_LAST_VALUE</title>
      <link>/en/sql-reference/functions/aggregate-functions/ts-last-value/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/ts-last-value/</guid>
      <description>
        
        
        &lt;p&gt;Processes the data that belongs to each time slice. A time series aggregate (TSA) function, &lt;code&gt;TS_LAST_VALUE&lt;/code&gt; returns the value at the end of the time slice, where an interpolation scheme is applied if the timeslice is missing. In this case the value is determined by the values corresponding to the previous (and next) timeslices based on the interpolation scheme of const (linear).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TS_LAST_VALUE&lt;/code&gt; returns one output row per time slice, or one output row per partition per time slice if partition expressions are specified.&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;TS_LAST_VALUE ( &lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt; [ IGNORE NULLS ] [, { &amp;#39;CONST&amp;#39; | &amp;#39;LINEAR&amp;#39; } ] )
&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;An &lt;code&gt;INTEGER&lt;/code&gt; or &lt;code&gt;FLOAT&lt;/code&gt; expression on which to aggregate and interpolate.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;IGNORE NULLS&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;The &lt;code&gt;IGNORE NULLS&lt;/code&gt; behavior changes depending on a &lt;code&gt;CONST&lt;/code&gt; or &lt;code&gt;LINEAR&lt;/code&gt; interpolation scheme. 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; in Analyzing Data for details.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;&#39;CONST&#39; | &#39;LINEAR&#39;&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies the interpolation value as constant or linear:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;CONST&lt;/code&gt; (default): New value is interpolated based on previous input records.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;LINEAR&lt;/code&gt;: Values are interpolated in a linear slope based on the specified time slice.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;You must use the &lt;code&gt;ORDER BY&lt;/code&gt; clause with a &lt;code&gt;TIMESTAMP&lt;/code&gt; column.&lt;/p&gt;
&lt;h2 id=&#34;multiple-time-series-aggregate-functions&#34;&gt;Multiple time series aggregate functions&lt;/h2&gt;
&lt;p&gt;The same query can call multiple time series aggregate functions. They share the same gap-filling policy as defined by the &lt;a href=&#34;../../../../en/sql-reference/statements/select/timeseries-clause/#&#34;&gt;TIMESERIES clause&lt;/a&gt;; however, each time series aggregate function can specify its own interpolation policy. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol,
TS_FIRST_VALUE(bid, &amp;#39;const&amp;#39;) fv_c,
       TS_FIRST_VALUE(bid, &amp;#39;linear&amp;#39;) fv_l,
       TS_LAST_VALUE(bid, &amp;#39;const&amp;#39;) lv_c
FROM TickStore
TIMESERIES slice_time AS &amp;#39;3 seconds&amp;#39;
OVER(PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/&#34;&gt;Gap Filling and Interpolation&lt;/a&gt; in Analyzing Data.&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/aggregate-functions/ts-first-value/#&#34;&gt;TS_FIRST_VALUE&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;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VAR_POP [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/var-pop-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/var-pop-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Evaluates the population variance for each member of the group. This is defined as the sum of squares of the difference of *&lt;code&gt;expression&lt;/code&gt;*from the mean of &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;, divided by the number of remaining rows:&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;)
&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. &lt;code&gt;VAR_POP&lt;/code&gt; returns the same data type as &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;related-functions&#34;&gt;Related functions&lt;/h2&gt;
&lt;p&gt;This aggregate function differs from analytic function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/var-pop-analytic/#&#34;&gt;VAR_POP&lt;/a&gt;&lt;/code&gt;, which computes the population variance of the current row with respect to the 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;.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the population variance for each household ID in the &lt;code&gt;customer&lt;/code&gt; table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT VAR_POP(household_id) FROM customer_dimension;
    var_pop
------------------
 74847050.0168393
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VAR_SAMP [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/var-samp-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/var-samp-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Evaluates the sample variance for each row of the group. This is defined as 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 remaining rows minus 1:&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;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; )
&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. &lt;code&gt;VAR_SAMP&lt;/code&gt; returns the same data type as &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;related-functions&#34;&gt;Related functions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;VAR_SAMP&lt;/code&gt; is semantically identical to nonstandard function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/variance-aggregate/#&#34;&gt;VARIANCE&lt;/a&gt;&lt;/code&gt;, which is provided for compatibility with other databases.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This aggregate function differs from analytic function 
&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;, which computes the sample variance of the current row with respect to the 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;.&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 returns the sample variance for each household ID in the &lt;code&gt;customer&lt;/code&gt; table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT VAR_SAMP(household_id) FROM customer_dimension;
     var_samp
------------------
 74848598.0106764
(1 row)
&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/aggregate-functions/variance-aggregate/#&#34;&gt;VARIANCE [aggregate]&lt;/a&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: VARIANCE [aggregate]</title>
      <link>/en/sql-reference/functions/aggregate-functions/variance-aggregate/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/variance-aggregate/</guid>
      <description>
        
        
        &lt;p&gt;Evaluates the sample variance for each row of the group. This is defined as 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 remaining rows minus 1.&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;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;VARIANCE ( &lt;span class=&#34;code-variable&#34;&gt;expression&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. &lt;code&gt;VARIANCE&lt;/code&gt; returns the same data type as &lt;em&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/em&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;related-functions&#34;&gt;Related functions&lt;/h2&gt;
&lt;p&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/aggregate-functions/var-samp-aggregate/#&#34;&gt;VAR_SAMP&lt;/a&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This aggregate function differs from analytic function 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/analytic-functions/variance-analytic/#&#34;&gt;VARIANCE&lt;/a&gt;&lt;/code&gt;, which computes the sample variance of the current row with respect to the 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;.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example returns the sample variance for each household ID in the &lt;code&gt;customer&lt;/code&gt; table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT VARIANCE(household_id) FROM customer_dimension;
     variance
------------------
 74848598.0106764
(1 row)
&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/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: WITHIN GROUP ORDER BY clause</title>
      <link>/en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/functions/aggregate-functions/within-group-order-by-clause/</guid>
      <description>
        
        
        &lt;p&gt;Specifies how to sort rows that are grouped by aggregate functions, one of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/argmax-agg/#&#34;&gt;ARGMAX_AGG&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/argmin-agg/#&#34;&gt;ARGMIN_AGG&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/collection-functions/implode/#&#34;&gt;IMPLODE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/listagg/#&#34;&gt;LISTAGG&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This clause is also supported for user-defined aggregate functions.&lt;/p&gt;
&lt;p&gt;The order clause only specifies order within the result set of each group. The query can have its own &lt;a href=&#34;../../../../en/sql-reference/statements/select/order-by-clause/&#34;&gt;ORDER BY&lt;/a&gt; clause, which has precedence over order that is specified by WITHIN GROUP ORDER BY, and orders the final result set.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITHIN GROUP (ORDER BY
  { &lt;span class=&#34;code-variable&#34;&gt;column-expression&lt;/span&gt; [ ASC | DESC [ NULLS { FIRST | LAST | AUTO } ] ]
  }[,...])
&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;column-expression&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;A column, constant, or arbitrary expression formed on columns, on which to sort grouped rows.&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;NULLS {FIRST | LAST | AUTO}&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies whether to position null values first or last. Default positioning depends on whether the sort order is ascending or descending:
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Ascending default: &lt;code&gt;NULLS LAST&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Descending default: &lt;code&gt;NULLS FIRST&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you specify &lt;code&gt;NULLS AUTO&lt;/code&gt;, OpenText™ Analytics Database chooses the positioning that is most efficient for this query, either &lt;code&gt;NULLS FIRST&lt;/code&gt; or &lt;code&gt;NULLS LAST&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you omit all sort qualifiers, the database uses &lt;code&gt;ASC NULLS LAST&lt;/code&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;For usage examples, see these functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/argmax-agg/#&#34;&gt;ARGMAX_AGG&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/argmin-agg/#&#34;&gt;ARGMIN_AGG&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/data-type-specific-functions/collection-functions/implode/#&#34;&gt;IMPLODE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/listagg/#&#34;&gt;LISTAGG&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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