天天看點

hive實操四(訂單及訂單類型行列互換)

資料:

111 N 10:00
111 A 10:05
111 B 10:10
           

期望結果:

order_id order_type_1 order_type_2 order_time_1 order_time_2
   111        N             A         10:00        10:05 
   111        A             B         10:05        10:10
           

所用SQL

create table order_type(
order_id  string,
order_type  string,
order_time string

)
row format delimited
fields terminated by '\t'
;

load data local inpath '/hivedata/order_type.txt' overwrite into table
order_type;

select * from
(select
order_id,
lag(order_type) over(distribute by order_id sort by order_time) order_type_1,
order_type order_type_2,
lag(order_time) over(distribute by order_id sort by order_time) order_time_1,
order_time order_time_2
from order_type) tmp
where order_type_1 is not null
;
           

.

.

.

.

.

下面是我的公衆号,收集了現在主流的大資料技能和架構,歡迎大家一起來學習交流。

hive實操四(訂單及訂單類型行列互換)

繼續閱讀