ホームページ  >  記事  >  データベース  >  HIVE分析函数

HIVE分析函数

WBOY
WBOYオリジナル
2016-06-07 16:13:21940ブラウズ

hive支持的分析函数: 总的概括 : http://www.2cto.com/os/201504/387681.html ******************************************************************************************************** Rank over的用法 :http://www.cnblogs.com/mycoding/archive/2

hive支持的分析函数:

总的概括
http://www.2cto.com/os/201504/387681.html

********************************************************************************************************

Rank over的用法:http://www.cnblogs.com/mycoding/archive/2010/05/29/1747065.html

原始数据:

a b c
----------- ----------- ----
1 3 E
2 4 A
3 2 D
3 5 B
4 2 C
2 4 B

需求:以a,b进行分组,在每个组内以b进行排名。

select *,rank() over( partition by a,b order by b) from xxxx_tab ;

数据为:

a b c rank
----------- ----------- ---- --------------------
1 3 E 1
2 4 A 1
2 4 B 1
3 2 D 1
3 5 B 2
4 2 C 1

分了5个组,第2行跟第3行是一个组,其他的每行是一个组。在第2行与第3行的组内以b排名,并列为1

***************************************************************************************************************************************

 

Row_Number() over的用法:http://www.cnblogs.com/fxgachiever/archive/2010/09/15/1826792.html

原始数据:

empid deptid 【本文来自鸿网互联 (http://www.68idc.cn)】salary



1 10 5500.00
2 10 4500.00
3 20 1900.00
4 20 4800.00
5 40 6500.00
6 40 14500.00
7 40 44500.00
8 50 6500.00
9 50 7500.00

需求:根据部门分组,显示每个部门的工资等级

 

SQL脚本:

SELECT *, Row_Number() OVER (partition by deptid ORDER BY salary desc) rank FROM employee

预期结果:

empid deptid salary rank
----------- ----------- --------------------------------------- --------------------
1 10 5500.00 1
2 10 4500.00 2
4 20 4800.00 1
3 20 1900.00 2
7 40 44500.00 1
6 40 14500.00 2
5 40 6500.00 3
9 50 7500.00 1
8 50 6500.00 2

********************************************************************************************

窗口函数的用法:http://blog.csdn.net/cnham/article/details/6101199

select month,sum(tot_sales) month_sales, sum(sum(tot_sales)) over(order by month rows between unbounded preceding and unbounded following) total_sales from orders group by month.

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。