EduCoder-Hive基本查询操作(一、二)-答案-路漫漫远俢兮

第一关:

//查询出工作职责涉及hive的并且工资大于8000的公司名称以及工作经验。
SELECT  workingExp ,company_name  FROM table1
 where responsibility LIKE '%hive%' AND  salary>8000 ;

第二关:

//计算不同工作年限以及其平均工资并且过滤出平均工资大于10000的
select avg(salary) as avgsalary,workingExp from table1 group by workingExp having avgsalary > 10000;

第三关:

//求出表table2中所有城市名的平均工资
select AVG(table1.salary),table2.city_name from 
table2 left outer join table1 on table2.city_code=table1.city_code
group by table2.city_name ;

第四关(二):

//查询出2013年7月22日的哪三种股票买入量最多
select securityid,sum(bidsize1) s from total where tradedate ='20130722' 
group by securityid order by s desc limit 3;

第五关(二):

//2013年7月25日每种股票总共被客户买入了多少元
select securityid,sum(cast(bidpx1 as float)*bidsize1) from total where tradedate="20130725"
group by securityid;

第六关(二):

//计算每个股票每天的交易量
//采用桶表抽样的方法(从第二个桶开始抽样,每隔两个开始抽样);
//创建分桶表total_bucket(以股票ID进行分桶);
//数据从total表获取。
create table if not exists total_bucket(
tradedate string,
securityid string,
bidsize1 int,
bidsize2 int
)clustered by(securityid) into 6 buckets
row format delimited fields terminated by ','
stored as textfile;

set hive.enforce.bucketing = true;

insert overwrite table total_bucket
select tradedate,securityid,bidsize1,bidsize2
from total;

select tradedate,securityid,sum(bidsize1+bidsize2) from total_bucket tablesample(bucket 2 out of 2 on securityid) group by tradedate,securityid;

 

座右铭:站在别人的思想上,看见自己的不足,传播错误的经验,愿君不重蹈覆辙。

 

由于受限于本人经验,难免不足,如有建议,欢迎留言交流。

 

说明:如果喜欢,请点赞,您的鼓励是本人前进的最好动力。

 

 

 

 

 

 

你可能感兴趣的:(hadoop相关学习,数据库)