TD_Histogram Function Example | Teradata Vantage - TD_Histogram Example - Teradata® Database

Database Analytic Functions

Product
Teradata® Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
Teradata_Vantage™___Advanced_SQL_Engine_Analytic_Functions.withLogo_upload_July2021/wnd1589838592459.ditamap
dita:ditavalPath
Teradata_Vantage™___Advanced_SQL_Engine_Analytic_Functions.withLogo_upload_July2021/ayr1485454803741.ditaval
dita:id
B035-1206
lifecycle
previous
Product Category
Teradata Vantage™

Input

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.

  • InputTable: hist_titanic_train
    passenger survived pclass name                                 sex    age sibsp parch ticket   fare      cabin       embarked 
     --------- -------- ------ ------------------------------------ ------ --- ----- ----- -------- --------- ----------- -------- 
            97        0      1 Goldschmidt; Mr. George B            male    71     0     0 PC 17754 34.6542     A5          C       
           488        0      1 Kent; Mr. Edward Austin              male    58     0     0 11771    29.7 	    B37         C       
           505        1      1 Maioni; Miss. Roberta                female  16     0     0 110152   86.5 	    B79         S       
           631        1      1 Barkworth; Mr. Algernon Henry Wilson male    80     0     0 27042    30 	    A23         S       
           873        0      1 Carlsson; Mr. Frans Olof             male    33     0     0 695      5 	    B51 B53 B55 S       
    
  • MinMax: hist_titanic_train_dim
    minVal    maxVal       label      
    --------- ---------    ---------- 
      0 	   20 		Young Age 
     21 	   45 		Middle Age
     46        91 		Old Age   
    

SQL Call

SELECT * FROM TD_Histogram (
  ON hist_titanic_train AS InputTable
  ON hist_titanic_train_dim AS MinMax DIMENSION
  USING
  TargetColumn ('age')
  MethodType ('variable-width')
  nbins (3)
) AS dt;

Output

Label      MinValue  MaxValue  CountOfValues bin_Percent 
 ---------- --------- --------- ------------- ----------- 
 Middle Age  21 	45             1   	20
 Old Age     46 	90             3   	60
 Young Age    0 	20             1   	20