**tip:**在hive中,如果从分析出计算当前的数据跟之前的状态数据有关(比如漏斗模型算转化率)--------->先把自己跟自己join–>就会把自己当前的状态数据跟之前的状态数据join起来出现在一行中。
例子:
create table t_salary_detail(username string,month string,salary int)
row format delimited fields terminated by ',';
load data local inpath '/root/hivedata/t_salary_detail.dat' into table t_salary_detail;
A,2015-01,5
A,2015-01,15
B,2015-01,5
A,2015-01,8
B,2015-01,25
A,2015-01,5
A,2015-02,4
A,2015-02,6
B,2015-02,10
B,2015-02,5
A,2015-03,7
A,2015-03,9
B,2015-03,11
B,2015-03,6
±-------------------------±----------------------±-----------------------±-+
| t_salary_detail.username | t_salary_detail.month | t_salary_detail.salary |
±-------------------------±----------------------±-----------------------±-+
| A | 2015-01 | 5 |
| A | 2015-01 | 15 |
| B | 2015-01 | 5 |
| A | 2015-01 | 8 |
| B | 2015-01 | 25 |
| A | 2015-01 | 5 |
| A | 2015-02 | 4 |
| A | 2015-02 | 6 |
| B | 2015-02 | 10 |
| B | 2015-02 | 5 |
| A | 2015-03 | 7 |