有一个订单表order。已知字段有:order_id(订单ID),user_id( 用户ID),amount(金额),pay_datetime(付费时间),channel_id(渠道ID),dt(分区字段)
1.在hive中创建这个表
create table order(
order_id string,
user_id string,
amount double,
pay_datetime timestamp,
channel_id string
)
partitioned by(dt string)
row format delimited fields terminated by ',';
2.查询dt=‘2018-09-01’里每个渠道的订单数,下单人数(去重),总金额
select
channel_id,
sum(amount) as s_amount,
count(distinct user_id) as d_user_id
from order group by channel_id
where dt = '2018-09-01';
3.查询dt=‘2018-09-01’里每个渠道的金额最大3笔订单
select
order_id,
rw
from
(
select
order_id,
row_number() over(partition by channel_id order by amount desc) rw
from order
where dt ='2018-09-01'
) t
where rw <=3;
4.有一天发现订单数据重复,请分析原因
(1)网络原因 (2) 一个订单同一个用户买了多个商品,每个商品一条数据也有可能造成订单id重复

关注 易学在线 公众号
每日更新大量优质技术文档
第一时间获知最新上架课程
与众多大数据猿分享与交流
DOIT.EDU 资料来自网络收集整理,如有侵权请告知