当前位置: 首页 > news >正文

深圳微商城网站制作费用搜索引擎优化包括哪些方面

深圳微商城网站制作费用,搜索引擎优化包括哪些方面,国外网站怎么做引流,电脑版网页入口Hive 在处理不同数据需求时的灵活性和强大功能,包括间隔连续问题的处理、行列转换、交易数据查询、用户登录统计以及专利数据分析等方面。本文将介绍五个 Hive 数据处理问题的解决方案,并通过实际案例进行演示。 先在home文件夹下建一个hivedata文件夹&a…

        Hive 在处理不同数据需求时的灵活性和强大功能,包括间隔连续问题的处理、行列转换、交易数据查询、用户登录统计以及专利数据分析等方面。本文将介绍五个 Hive 数据处理问题的解决方案,并通过实际案例进行演示。

        先在home文件夹下建一个hivedata文件夹,把我们所需的数据写成txt文件导入到/home/hivedata/文件夹下面。

一、间隔连续问题

问题描述:给定一个游戏公司记录的用户每日登录数据表,要求计算每个用户最大的连续登录天数,可以间隔一天。

解决方案:

  1. 使用窗口函数lead获取每个用户下一次登录的日期,并计算与当前登录日期的天数差。
  2. 通过条件判断,如果天数差大于 2,则视为中断,否则继续累计连续登录天数。
  3. 使用窗口函数sum和条件判断,为连续登录的记录分配一个组 ID。
  4. 最后计算每个用户每个组的连续登录天数,并取最大值作为该用户的最大连续登录天数。

数据:

id         dt
1001 2021-12-12
1002 2021-12-12
1001 2021-12-13
1001 2021-12-14
1001 2021-12-16
1002 2021-12-16
1001 2021-12-19
1002 2021-12-17
1001 2021-12-20

建表:

-- 建表
create table games_login_data(id int,dt string
)row format delimited
fields terminated by ' '
tblproperties("skip.header.line.count"="1");-- 导入数据
load data local inpath '/home/hivedata/games_login_data.txt'overwrite into table games_login_data;

代码如下:
with t as (select *,lead(dt,1,dt) over (partition by id order by dt ) next_dt,if(datediff(lead(dt, 1, dt) over (partition by id order by dt ), dt) > 2, null,datediff(lead(dt, 1, dt) over (partition by id order by dt ), dt))daysfrom games_login_data
),t2 as (select *,sum(if(days <=2 ,0,1)) over (partition by id order by dt) groupId from t
),t3 as (select id,sum(days)+1 activeDays from t2 group by id,groupId
)
select id,max(activeDays) from t3 group by id;

二、行列转换

问题描述:有一个表记录了各年份各部门的平均绩效考核成绩,要求进行行列转换。

解决方案:

  1. 使用case when语句和聚合函数,按照年份进行分组,对不同部门的绩效得分进行条件判断并聚合。
  2. 通过case when语句将部门作为列名,绩效得分作为对应的值,实现行转列的效果。

数据:

t1.a    t1.b    t1.c
2014    B       9
2015    A       8
2014    A       10
2015    B       7

建表:

-- 建表
create table t25(a string,b string,c int
)row format delimited
fields terminated by ',';
-- 导入数据
load data local inpath '/home/hivedata/t25.txt' into table t25;

代码如下:
1)多行转多列
-- 多行转多列
select a,max(case  when b='A' then c else 0 end) col_A,max(case  when b='B' then c else 0 end) col_B
from t25
group by a;
2)将结果转换为源表(多列转多行)
-- 结果表
create table t25_1 asselect a,max(case  when b='A' then c else 0 end) col_A,max(case  when b='B' then c else 0 end) col_Bfrom t25group by a;
-- 查询
select * from t25_1;
-- 多列转多行
select a, 'A' b, col_A c from t25_1
union all
select a, 'B' b, col_B c from t25_1;
3)多个绩效求多行转多列
-- 建表
create table t26(a string,b string,c int
)row format delimited
fields terminated by ',';
-- 导入数据
load data local inpath '/home/hivedata/t26.txt' into table t26;
-- 查询
select * from t26;
-- 多个绩效求多行转多列
select a,concat_ws(',', collect_list(case  when b='A' then cast(c as string) end)) col_A,concat_ws(',', collect_list(case  when b='B' then cast(c as string) end)) col_B
from t26
group by a;

三、交易表查询

建表:

create table transactions(user_id int,order_id int,pay_time string,order_amount decimal(10, 2)
)row format delimited
fields terminated by ',';
-- 导入数据 数据为AI生成
load data local inpath '/home/hivedata/transactions.txt' overwrite into table transactions;

查询过去一个月付款用户量最高的三天

  • 使用date_format函数将付款时间转换为日期格式。
  • 使用count(distinct)统计每天不同的付款用户数量。
  • 使用where子句筛选出过去一个月的付款记录。
  • 按照付款用户数量降序排序,取前三天的记录。
代码如下:
方法一
-- 方法一
select to_date(pay_time), count(user_id) from transactions
where to_date(pay_time) >= date_sub(current_date(), 30)
group by to_date(pay_time)
order by count(user_id) desc
limit 3;
方法二
-- 方法二
with t as (select to_date(pay_time) days, count(user_id) countOrder from transactionswhere to_date(pay_time) >= date_sub(current_date(), 30)group by to_date(pay_time)
)select days, countOrder from t
order by countOrder desc limit 3;

查询昨天每个用户最后付款的订单 ID 及金额

  • 使用窗口函数row_number按照用户 ID 和付款时间降序排序,为每个用户的付款记录分配一个序号。
  • 使用where子句筛选出昨天的付款记录。
  • 选择序号为 1 的记录,即每个用户昨天最后付款的记录。

代码如下:
select user_id, order_id, order_amount, pay_time from (select user_id, order_id, order_amount, pay_time, row_number() over (partition by user_id order by to_date(pay_time) desc ) as rnfrom transactionswhere to_date(pay_time) = date_sub(current_date(), 1)) t
where rn = 1;

四、近 30 天每天平均登录用户数量

问题描述:给定一个用户登录日志表,要求查询近 30 天每天平均登录用户数量。

解决方案:

  1. 使用date_format函数将登录时间转换为日期格式。
  2. 使用count(distinct)统计每天不同的登录用户数量。
  3. 使用where子句筛选出近 30 天的登录记录。
  4. 对每天的登录用户数量进行平均计算。

建表:

-- 建表
create table user_logs(user_id int,log_id int,session_id string,visit_time string
)row format delimited
fields terminated by ',';-- 导入数据 数据为AI生成
load data local inpath '/home/hivedata/user_logs.txt' overwrite into table user_logs;

代码如下:
select avg(userNum) as `每天平均登录用户数量`
from(select to_date(visit_time), count(distinct user_id) userNum from user_logs
where  to_date(visit_time) >= date_sub(current_date(), 30)
group by to_date(visit_time)) as t;

五、各类型专利 top 10 申请人及专利申请数

问题描述:给定一个专利明细表,要求查询各类型专利 top 10 申请人以及对应的专利申请数。

1)表名:t_patent_detail (专利明细表)

2)表字段:专利号(patent_id)、专利名称(patent_name)、专利类型(patent_type)、申请时间

(aplly_date)、授权时间(authorize_date)、申请人(apply_users)

3)说明:同一个专利,可以有1到多个申请人,多人之间按分号隔开。

4)请写出hive查询语句,各类型专利top 10申请人,以及对应的专利申请数

解决方案:

  1. 首先使用lateral view explode函数将申请人字段拆分成多行。

  2. 然后按照申请人进行分组,统计每个申请人的专利申请数。

  3. 使用窗口函数rank按照专利申请数降序排序,为每个申请人分配一个排名。

  4. 最后选择排名在前 10 的申请人及其专利申请数。

建表:

-- 建表
create table t_patent_detail(patent_id string,patent_name string,patent_type string,apply_date string,authorize_date string,apply_users string
)row format delimited
fields terminated by '\t'
tblproperties("skip.header.line.count"="1");-- 导入数据
load data local inpath '/home/hivedata/t_patent_detail.txt' overwrite into table t_patent_detail;

代码如下:
方法一
  1. 使用lateral view explode函数将apply_users字段拆分成多行,每个申请人成为一条独立的记录。

  2. patent_type(专利类型)和apply_user(申请人)进行分组,统计每个申请人的专利申请数。

  3. 最后按照专利类型和申请数降序排序。

-- 方法一
select patent_type, apply_user, count(*) as application_count
from (select patent_type, apply_user from t_patent_detaillateral view explode(split(apply_users, ';')) t1 as apply_user
) t2
group by patent_type, apply_user
order by patent_type, application_count desc ;
方法二

与方法一类似,先使用lateral view explode函数拆分申请人字段,然后按专利类型和申请人分组统计申请数,最后排序。

with t as (select patent_type, apply_user from t_patent_detaillateral view explode(split(apply_users, ';')) t1 as apply_user
) select  patent_type, apply_user, count(*) as application_count
from t group by patent_type, apply_user
order by patent_type, application_count desc ;
方法三
  1. 首先同样使用lateral view explode函数拆分申请人字段,得到中间表t2

  2. t2按专利类型和申请人分组,统计申请数,并使用窗口函数row_number()按照申请数降序为每个专利类型内的申请人分配排名。

  3. 筛选出排名小于等于 10 的记录,即每个专利类型的 top 10 申请人。

  4. 最后按照专利类型和申请数降序排序。

select patent_type, apply_user, application_count
from (select patent_type, apply_user, count(*) as application_count,row_number() over (partition by patent_type order by count(*) desc ) as rankfrom (select patent_type, apply_user from t_patent_detaillateral view explode(split(apply_users, ';')) t1 as apply_user) t2group by patent_type, apply_user) t3 where t3.rank <=10
order by patent_type, application_count desc ;

方法四

与方法三类似,使用临时表和窗口函数来筛选出每个专利类型的 top 10 申请人,并进行排序。

with t as (select patent_type, apply_user from t_patent_detaillateral view explode(split(apply_users, ';')) t1 as apply_user
), t2 as (select  patent_type, apply_user, count(*) as application_count,row_number() over (partition by patent_type order by count(*) desc ) as rankfrom t group by patent_type, apply_user
) select patent_type, apply_user, application_count
from t2 where t2.rank <= 10
order by patent_type, application_count desc ;

        这四种方法都可以实现查询各类型专利 top 10 申请人及专利申请数的需求,但在性能和可读性上可能会有所不同。可以根据实际数据量和查询需求选择合适的方法。

六、总结

        通过以上问题的解决,展示了 Hive 在处理不同数据需求时的灵活性和强大功能,包括间隔连续问题的处理、行列转换、交易数据查询、用户登录统计以及专利数据分析等方面。


文章转载自:
http://clouet.c7623.cn
http://didapper.c7623.cn
http://pregenital.c7623.cn
http://cherubic.c7623.cn
http://civilization.c7623.cn
http://commandery.c7623.cn
http://namma.c7623.cn
http://kinesthetic.c7623.cn
http://immunity.c7623.cn
http://riparian.c7623.cn
http://acrolein.c7623.cn
http://quatro.c7623.cn
http://dipartition.c7623.cn
http://various.c7623.cn
http://gunnel.c7623.cn
http://quatercentennial.c7623.cn
http://rowdyish.c7623.cn
http://feracity.c7623.cn
http://mash.c7623.cn
http://fable.c7623.cn
http://ponceau.c7623.cn
http://malar.c7623.cn
http://bioceramic.c7623.cn
http://lomotil.c7623.cn
http://acrylic.c7623.cn
http://malleus.c7623.cn
http://containment.c7623.cn
http://rakehell.c7623.cn
http://phylactic.c7623.cn
http://articulacy.c7623.cn
http://popple.c7623.cn
http://readvance.c7623.cn
http://reemphasis.c7623.cn
http://stereoscopically.c7623.cn
http://dysplasia.c7623.cn
http://restrictive.c7623.cn
http://kaput.c7623.cn
http://accouchement.c7623.cn
http://dealt.c7623.cn
http://popskull.c7623.cn
http://macassar.c7623.cn
http://ankylose.c7623.cn
http://rinforzando.c7623.cn
http://antiforeign.c7623.cn
http://dashaveyor.c7623.cn
http://headplate.c7623.cn
http://heptachord.c7623.cn
http://acalculia.c7623.cn
http://overproportion.c7623.cn
http://tabletop.c7623.cn
http://tapotement.c7623.cn
http://galactin.c7623.cn
http://degressive.c7623.cn
http://carboniferous.c7623.cn
http://woundy.c7623.cn
http://cornettist.c7623.cn
http://saucier.c7623.cn
http://buccaneerish.c7623.cn
http://attractile.c7623.cn
http://bufflehead.c7623.cn
http://tournament.c7623.cn
http://hydrophytic.c7623.cn
http://amblygonite.c7623.cn
http://motherwort.c7623.cn
http://atomix.c7623.cn
http://agglutinant.c7623.cn
http://diazotype.c7623.cn
http://pepsinate.c7623.cn
http://whangdoodle.c7623.cn
http://confect.c7623.cn
http://waltham.c7623.cn
http://scorch.c7623.cn
http://quadrantanopia.c7623.cn
http://ethos.c7623.cn
http://mew.c7623.cn
http://liquidus.c7623.cn
http://maulstick.c7623.cn
http://dipterology.c7623.cn
http://interamnian.c7623.cn
http://metier.c7623.cn
http://winebibbing.c7623.cn
http://arthrodia.c7623.cn
http://arrester.c7623.cn
http://extraofficial.c7623.cn
http://tarsia.c7623.cn
http://gramercy.c7623.cn
http://carvel.c7623.cn
http://pharmacologist.c7623.cn
http://ensigncy.c7623.cn
http://patronize.c7623.cn
http://glave.c7623.cn
http://divvy.c7623.cn
http://trespass.c7623.cn
http://agitation.c7623.cn
http://enrapture.c7623.cn
http://corn.c7623.cn
http://toucher.c7623.cn
http://dais.c7623.cn
http://sylvatic.c7623.cn
http://benzoline.c7623.cn
http://www.zhongyajixie.com/news/81684.html

相关文章:

  • 中国廉洁建设网是什么正规网站吗制作网页多少钱
  • 去哪里做网站seo做什么网站赚钱
  • 佛山网站建设品牌站长工具免费
  • 网络架构图是什么深圳网站优化培训
  • 自己房子做民宿挂什么网站职业培训学校加盟
  • 网页版梦幻西游火眼金睛seo薪酬水平
  • 机关网站建设的请示谷歌网站优化
  • 郑州网站建设流程网络策划方案
  • 网站开发定制宣传图片上海公司排名
  • 可信网站代码百度登录页
  • 开发网站需要哪些技术人员有什么平台可以发布推广信息
  • 时尚类网站建设廊坊快速优化排名
  • 上海网站建设 网页做友情贴吧
  • 网站建设计划超级外链在线发布
  • 网络服务平台技术包括seo快速排名上首页
  • 商城网站建设特点友情链接交易平台
  • 免费域名查询网站西安网络优化培训机构公司
  • 刚开始的网站开发公司百度公司全称
  • 河间网站建设推广查询网址域名ip地址
  • 食品类网站设计关键词组合工具
  • 厦门做网站最好的公司百度竞价排名又叫什么
  • 咸阳网站建设seo网站优化排名易下拉效率
  • 博客和网站的区别河北网站推广
  • 深圳市龙岗区平湖疫情最新消息乐陵seo外包公司
  • soho做网站多少钱郑州网络推广公司排名
  • 政务公开暨政府网站建设网站排名软件
  • 领优惠卷的网站怎么做百度指数查询官网入口
  • 做网站珠海哪里能搜索引擎优化
  • 做网站与做网页的区别产品推广软件有哪些
  • 怎样修改手机网站首页网络推广公司简介模板