hql三

  1. 请创建Hive分区表表名为sockinfo,按照行业进行分区,分区字段名自定义。

create table sockinfo_tmp(

  id int,

  stockno string,

  stockname string,

  trade string,

  platform string,

  volume int)

row format delimited fields terminated by ','

stored as textfile;

 

load data local inpath '/home/test/hive-2.3.7/data/gupiao.txt' into table sockinfo_tmp;

 

create table sockinfo(

  id int,

  stockno string,

  stockname string,

  trade string,

  platform string,

  volume int)

partitioned by (trade_p string)

row format delimited fields terminated by ','

stored as textfile;

 

  1. 将以上信息导入到Hive表中。

insert into sockinfo partition(trade_p) select *,

case when  trade='5G通讯' then '5Gtongxun' when  trade='医疗' then 'yiliao' 

when  trade='环保' then 'huanbao'   when  trade='高端制造' then 'gaoduanzhizao'

else 'guofangjungong' end as trade_p from sockinfo_tmp;

 

  1. 按交易平台统计交易额前3的记录。

select * from (select *,row_number() over(partition by platform order by volume desc) rank from sockinfo)t where t.rank<=3;

3)创建Hive自定义函数,功能是根据平台区分平台性质同花顺,钱龙 为国营,其余为私营。(核心)

public class TypeUDF extends UDF {

    public String evaluate(String platform) {

        String type = null;

        if ("同花顺".equals(platform) || "钱龙".equals(platform)) {

            type = "国营";

        } else {

            type = "私营";

        }

        return type;

    }

}

4)查询5G通讯分区对应的所有数据,信息包括:股票号 股票名称 行业 交易平台 ,平台性质。(6分)

select *,getType(platform) type from sockinfo where trade_p='5Gtongxun';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值