例 - Teradata Database - Teradata Vantage NewSQL Engine - 順序付き分析関数の例。

Teradata Vantage™ SQL関数、演算子、式および述部

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
2019年3月
Language
日本語
Last Update
2019-10-29
dita:mapPath
ja-JP/xzf1512079057909.ditamap
dita:ditavalPath
ja-JP/xzf1512079057909.ditaval
dita:id
B035-1145
Product Category
Software
Teradata Vantage

以下の例は、Marital Status (結婚状況)に対するGender (性別)の頻度を計算するSQL問合わせが、どのようにTeradata Warehouse Minerを使用するかを示したものです。

SELECT gender, marital_status, xcnt,xpct
   ,CSUM(xcnt, xcnt DESC, gender, marital_status) AS xcum_cnt
   ,CSUM(xpct, xcnt DESC, gender, marital_status) AS xcum_pct
   ,RANK(xcnt DESC, gender ASC, marital_status ASC) AS xrank
FROM  
   (SELECT gender, marital_status, COUNT(*) AS xcnt
      ,100.000 * xcnt / xall (FORMAT 'ZZ9.99') AS xpct
   FROM customer_table A,
      (SELECT COUNT(*) AS xall
      FROM customer_table) B
GROUP BY gender, marital_status, xall
HAVING xpct >= 1) T1
QUALIFY xrank <= 8
ORDER BY xcnt DESC, gender, marital_status

この問合わせの結果は、以下のテーブルのようになります。

gender marital_status xcnt xpct xcum_cnt xcum_pct xrank
F Married 3910093 36.71 3910093 36.71 1
M Married 2419511 22.71 6329604 59.42 2
F Divorced 1612130 15.13 7941734 74.55 3
M Divorced 1412624 3.26 9354358 87.81 4
F Single 491224 4.61 9845582 92.42 5
F Widowed 319881 3.01 10165463 95.43 6
M Single 319794 3.00 10485257 98.43 7
M Widowed 197131 1.57 10652388 100.00 8