Ordered Analytical Functions Window Examples | Teradata Vantage - Example: Group Count - Analytics Database - Teradata Vantage

SQL Functions, Expressions, and Predicates

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-01-12
dita:mapPath
obm1628111499646.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
kby1472250656485
lifecycle
latest
Product Category
Teradata Vantageā„¢

The following SQL query might yield the results that follow it, where the group count for sales is returned for each of the four partitions defined by city and kind. Notice that rows that have no sales are not counted.

   SELECT city, kind, sales, profit,
   COUNT(sales) OVER (PARTITION BY city, kind 
                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                      UNBOUNDED FOLLOWING)
   FROM activity_month;

Result:

   city     kind      sales  profit  Group Count(sales)
   -------  --------  -----  ------  ------------------
   LA       Canvas       45     320                   4
   LA       Canvas      125     190                   4
   LA       Canvas      125     400                   4
   LA       Canvas       20     120                   4
   LA       Leather      20      40                   1
   LA       Leather       ?       ?                   1
   Seattle  Canvas       15      30                   3
   Seattle  Canvas       20      30                   3
   Seattle  Canvas       20     100                   3
   Seattle  Leather      35      50                   1
   Seattle  Leather       ?       ?                   1