建外部表,之前hadoop职位统计就是这么做的

hive> drop table job;

OK

Time taken: 5.446 seconds

hive> show tables;

OK

Time taken: 0.018 seconds

hive> create external table job(area string, experience string, degree string,

> num string, salary string)

> row format delimited fields terminated by ','

> location '/job';#在hdfs先建好这个文件夹,并上传好数据

OK

Time taken: 0.103 seconds

hive> select * from job;

OK

北京3-5年本科3人 15001-20000元/月

北京1-3年本科3人 10001-15000元/月

杭州3-5年本科1人 15001-20000元/月

。。。

hive> select area, count(area) from job group by area;

建表

hive> create external table tctest(uid string,goodsid string,behtype string,space string,category string,time string)

hive> row format delimited fields terminated by ','

hive> location '/tianchitest';

将日期转化为时间戳

hive> select unix_timestamp(time,'yyyyMMddHH') from tctest;利用上面的函数+CTAS语句创建一个含时间戳的表

hive> create table tcc as select uid,goodsid,behtype,space,category,unix_timestamp(time,'yyyy-MM-dd HH') from tctest;

最好直接改列名

hive> create table tcc as select uid,goodsid,behtype,space,category,unix_timestamp(time,'yyyy-MM-dd HH') as time from tctest;

dual表

因为Hive里没有自带dual表,所以我们要自己建一个

hive> create table dual(dummy string);#之后建一个dual.txt里面写个值X

hive> load data local inpath '/home/guo/dual.txt' into table dual;

hive> select unix_timestamp("2014-12-18 23:59:59") from dual;

OK

1418918399

Time taken: 0.082 seconds, Fetched: 1 row(s)

hive> select unix_timestamp("2014-12-17 23:59:59") from dual;

OK

1418831999

Time taken: 0.112 seconds, Fetched: 1 row(s)

将时间戳转化为日期

hive> select from_unixtime(1418831999) from dual;

OK

2014-12-17 23:59:59

Time taken: 0.111 seconds, Fetched: 1 row(s)

查看表结构

hive> describe tcc;

OK

uid string

goodsid string

behtype string

space string

category string

_c5 bigint

Time taken: 0.025 seconds, Fetched: 6 row(s)修改列名,注意那是反引号

hive> alter table tcc change `_c5` time bigint;

OK

Time taken: 0.172 seconds

将hive表中内容导到本地

guo@guo:~$ hive -e "select * from tcpredict" >> predict.csv

开始的想法奉上(当时没有理解题意,想的也比较简单)

hive> create external table tclx(uid string,goodsid string,behtype string,space string,category string,time string)

hive> row format delimited fields terminated by ','

hive> location '/tianchilx';

hive> create table tianchi as select uid,goodsid,behtype,space,category,unix_timestamp(time,'yyyy-MM-dd HH') as time from tclx;

#改列名,不用了

hive> alter table tianchi change `_c5` time bigint;

0.0

hive> create table tct1 as select distinct uid from tianchi where behtype = 3 and time > 1418831999;

hive> create table tct2 as select t.* from tianchi t,tct1 c where t.uid=c.uid;

hive> select * from tct2 limit 5;#查看表的前五行数据

hive> create table tct3 as select distinct uid from tct2 where behtype=4;

hive> create table tct4 as select t.* from tct2 t,tct3 c where t.uid=c.uid;

改进一下

hive> create table tct6 as select c.* from (select distinct uid from tct2 where behtype=4)t,tct2 c where t.uid=c.uid;

或者,更直接一点

hive> create table tct7 as select c.* from

(select distinct uid from (select a.* from tianchi a,(select distinct uid from tianchi

where behtype=3 and time>1418831999) b

where a.uid=b.uid)t

where t.behtype=4)t,tct2 c

where t.uid=c.uid

或者,改进一点,用in

hive> create table tct8 as select c.* from

(select distinct uid from (select a.* from tianchi a where a.uid in (select distinct uid from tianchi

where behtype=3 and time>1418831999))b

where b.behtype=4)t,tct2 c

where t.uid=c.uid;再改进一点

hive> create table tct9 as select c.* from tct2 c

where c.uid in (select distinct uid from (select a.* from tianchi a where a.uid in (select distinct uid from tianchi

where behtype=3 and time>1418831999))b

where b.behtype=4);

下面来自:http://jingyan.baidu.com/article/9989c74604a644f648ecfef3.html

简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW_NUMBER() OVER (ORDER BY xlh DESC) 是先把xlh列降序,再为降序以后的没条xlh记录返回一个序号。

SELECT *, Row_Number() OVER (partition by deptid ORDER BY salary desc) rank FROM employee

根据部门分组,显示每个部门的工资等级

oracle 外部表 时间戳,Hive建立外部表与时间戳转换(含建dual表,修改列名,row_number() 函数等)...相关推荐

  1. mysql在表的某一位置增加一列、删除一列、修改列名

    如果想在一个已经建好的表中添加一列,可以用以下代码: alter table 表名 add column 列名 varchar(20) not null; 这条语句会向已有的表中加入一列,这一列在表的 ...

  2. mysql添加列名在第一列_mysql在表的某一位置增加一列、删除一列、修改列名

    如果想在一个已经建好的表中添加一列,可以用以下代码: alter table 表名 add column 列名 varchar(20) not null; 这条语句会向已有的表中加入一列,这一列在表的 ...

  3. ORACLE DUAL表详解

    看itpub上一个帖子:http://www.itpub.net/viewthread.php?tid=981212&extra=&page=1 想学习以下Oracle dual表. ...

  4. Oracle dual表详解(zzl)

    1.DUAL表的用途 Dual 是 Oracle中的一个实际存在的表,任何用户均可读取,常用在没有目标表的Select语句块中 --查看当前连接用户 SQL> select user from ...

  5. access找不到输入表或者dual_神奇的DUAL表总结

    ★★★★★★★★★★★本文档版权归个人所有,未经允许,禁止用于商业用途,违者必究★★★★★★★★★★★ 背景介绍:Oracle DUAL表是一个很神奇的东西,为什么说它神奇呢?DUAL表属于SYS用户 ...

  6. Oracle 视图(1)建立视图

    一. 视图是基于表的表或者视图的逻辑表,与储存数据的表一样都是Oracle的方案对象. 视图通常用于下面: 1.通过提供用户所需要的的基表中的数据,可以简化用户对数据的理解,隐藏表结构的复杂性,而且可 ...

  7. mysql中dual表

    1.楔子 今日在某项目数据库中发现每个库底下都有这样一张表,如下图所示: 这张表有且只能有一条数据,表结构如下所示: 我想这样做必然有其精神奥义和奇技淫巧,于是一探究竟. 2. mysql中模拟dua ...

  8. MySQL建员工表案例

    MySQL建员工表案例 create table DEPT( DEPTNO int(2) not null, DNAME VARCHAR(14), LOC VARCHAR(13) ); alter t ...

  9. hive建立内部表映射hbase_Hive 建外链表到 Hbase(分内部表、外部表两种方式)

    一. Hive 建内部表,链到hbase :特点:Hive drop表后,Hbase 表同步删除 drop table if exists hbase_kimbo_test1; CREATE TABL ...

最新文章

  1. bind98-内网智能DNS之master服务器构建
  2. python常用英语单词-3天教你掌握Python必备常用英语词汇
  3. c语言整形除法是五舍六入吗,四舍六入五成双 - C/C++论坛 - 51CTO技术论坛_中国领先的IT技术社区...
  4. ReportViewer教程(15)-矩阵报表-6
  5. 6间房,把评论添加到视频的metadata.
  6. 原生sql的各种问题
  7. Linux_Make(Makefile)
  8. php srs api,文档中心
  9. 程序员代码面试指南:IT 名企算法与数据结构题目最优解
  10. 数学建模-BP神经网络简介
  11. Linux安全模块(LSM)学习——简单的LSM demo(1)
  12. setBounds(left, top, right, bottom)详解
  13. 从网友评论中思考成长性思维和固定性思维
  14. Ipoe和Pppoe,宽带认证技术
  15. Excel中,把数字和汉字分开的方法
  16. LibreCAD环境配置
  17. 服务器怎么装虚拟打印机,虚拟打印机安装不成功的原因
  18. 安卓Android sqllite实现保存数据和读数据
  19. 04.ARM-mini2440-内存管理单元(MMU)
  20. 以太坊 权益证明(五)

热门文章

  1. 真机调试及上线简略流程
  2. 前端小结(5)---- iframe
  3. 【PHP入门到精通】:Ch05:字符串处理
  4. C# java 有关“字节序”的描述 .
  5. android studio炸包怎么导入,请问android studio如何引入包
  6. 初一辍学学php能行吗_《夺冠》破7亿,辍学的农村姑娘成排球女王,朱婷:百炼才能成钢...
  7. 分层和分段用什么符号_小编带你学直播——后牙树脂分层堆塑
  8. Asp.Net微信发布菜单,出现“invalid sub button url domain hint”错误
  9. Android板实现双屏显示,DisplayManager和Display的使用
  10. 有关性能测试结果的几点分析原则