文档首页 > > 工具指南> Migration Tool SQL语法迁移工具> Teradata语法迁移> 系统函数和操作符> 分析函数

分析函数

分享
更新时间: 2019/08/09 GMT+08:00

在Teradata中,分析函数统称为有序分析函数,它们为数据挖掘、分析和商业智能提供了强大的分析能力。

ORDER BY中的分析函数

输入:ORDER BY子句中的分析函数

SELECT customer_id, customer_name, RANK(customer_id, customer_address DESC) 
   FROM customer_t
 WHERE  customer_state = 'CA'
 ORDER BY RANK(customer_id, customer_address DESC);

输出

SELECT customer_id, customer_name, RANK() over(order by customer_id, customer_address DESC) 
   FROM customer_t
 WHERE  customer_state = 'CA'
 ORDER BY RANK() over(order by customer_id DESC, customer_address DESC) ;

输入:GROUP BY子句中的分析函数

SELECT customer_city, customer_state, postal_code
     , rank(postal_code)
     , rank() over(partition by customer_state order by postal_code)
    , rank() over(order by postal_code)
  FROM Customer_T 
  GROUP BY customer_state
  ORDER BY customer_state;

输出

SELECT customer_city, customer_state, postal_code
     , rank() over(PARTITION BY customer_state ORDER BY postal_code DESC) 
     , rank() over(partition by customer_state order by postal_code)
     , rank() over(order by postal_code)
  FROM Customer_T 
  ORDER BY customer_state;

PARTITION BY中的分析函数

当输入脚本的PARTITION BY子句中包含数值时,迁移脚本将原样保留该数值。

输入:PARTITION BY子句中的分析函数(包含数值)

SELECT
          Customer_id
          ,customer_name
          ,rank (
          ) over( partition BY 1 ORDER BY Customer_id )
          ,rank (customer_name)
     FROM
          Customer_t
     GROUP BY
          1
;

输出

SELECT
          Customer_id
          ,customer_name
          ,rank (
          ) over( partition BY 1 ORDER BY Customer_id )
          ,rank (
          ) over( PARTITION BY Customer_id ORDER BY customer_name DESC )
     FROM
          Customer_t
;
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

跳转到云社区