欢迎投稿

今日深度:

HIVE分析函数,

HIVE分析函数,


hive支持的分析函数:

总的概括http://www.07net01.com/linux/HIVE_chuangkoujifenxihanshu_yingyongchangjing_532180_1373989446.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      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.


www.htsjk.Com true http://www.htsjk.com/hive/34675.html NewsArticle HIVE分析函数, hive支持的分析函数: 总的概括 : http://www.07net01.com/linux/HIVE_chuangkoujifenxihanshu_yingyongchangjing_532180_1373989446.html ****************************************************************************...
相关文章
    暂无相关文章
评论暂时关闭