TD_UnivariateStatistics Example | UnivariateStatistics - Example: Using TD_UnivariateStatistics to Determine Mean, Median, and Mode - Analytics Database

Database Analytic Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-04-01
dita:mapPath
gjn1627595495337.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
jmh1512506877710
Product Category
Teradata Vantageā„¢

Every complete example in this document is available in a zip file that you can download. The zip file includes a SQL script file that creates the input tables for the examples. If you are reading this document on https://docs.teradata.com/, you can download the zip file from the attachment in the left sidebar.

TD_UnivariateStatistics InputTable: titanic_train

passenger survived  name                                 gender age  fare       
--------- --------  ----                                 ------ ---  ----       
       97        0  Goldschmidt; Mr. George B            male   71   34.6542        
      488        0  Kent; Mr. Edward Austin              male   58   29.7       
      505        1  Maioni; Miss. Roberta                female 16   86.5        
      631        1  Barkworth; Mr. Algernon Henry Wilson male   80   30        
      873        0  Carlsson; Mr. Frans Olof             male   33    5

TD_UnivariateStatistics SQL Call

SELECT * FROM TD_UnivariateStatistics (
  ON titanic_train AS InputTable
  USING
  TargetColumns ('age','fare')
  Stats ('MEAN', 'MEDIAN', 'MODE')
) AS dt;

TD_UnivariateStatistics Output

ATTRIBUTE StatName StatValue 
--------- -------- --------- 
age       MEAN      5.16000000000000E 001
age       MEDIAN    5.80000000000000E 001
age       MODE      1.60000000000000E 001
fare      MEAN      3.71708400000000E 001
fare      MEDIAN    3.00000000000000E 001
fare      MODE      5.00000000000000E 000