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

建外部表,之前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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/425965.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

http:(1):http简介

HTTP 简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议。。 HTTP是一个基于TCP/IP通信协议来传递数据(HTML 文件, …

[Leedcode][JAVA][第466题][统计重复个数][数组]

【问题描述】466. 统计重复个数 由 n 个连接的字符串 s 组成字符串 S,记作 S [s,n]。例如,["abc",3]“abcabcabc”。如果我们可以从 s2 中删除某些字符使其变为 s1,则称字符串 s1 可以从字符串 s2 获得。例如,根据定义…

phantomJs原理

引用文段:链接:https://www.jianshu.com/p/0254391918f7 网页渲染可分为服务端渲染和客户端渲染,前者是指你在浏览器地址栏输入一个网址,Web服务器处理请求过程就将所有需要呈现的html元素都构造好了,浏览器收到响应就…

oracle t44,SecureFiles LOBs基础知识之存储篇

SecureFiles LOBs相比于BasicFilesLOBs具有加密(encryption)、去重(deduplicaiton)、压缩(compression)等新功能,pctversion,chunksize等参数也仅仅为了向后兼容而保留,因此SecureFiles LOBs的自适应能力更强,在管理上更为简化&am…

http:(2):http请求方法

HTTP 请求方法 根据 HTTP 标准,HTTP 请求可以使用多种请求方法。 HTTP1.0 定义了三种请求方法: GET, POST 和 HEAD方法。 HTTP1.1 新增了六种请求方法:OPTIONS、PUT、PATCH、DELETE、TRACE 和 CONNECT 方法。 序 号 方法 描述 1 GET …

[Leedcode][JAVA][第200题][岛屿数量][DFS][BFS][并查集]

【问题描述】 第200题 岛屿数量 给你一个由 1(陆地)和 0(水)组成的的二维网格,请你计算网格中岛屿的数量。岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。此外&#xf…

python闯关_Day012

day012 用python实现信息卡管理及购物商城的项目 需求 #需求: 1 这是一个信用卡管理程序 2 用户手持信用卡购物,使用函数,按照软件开发规范 3 用户名密码存放于文件中,支持多用户登陆,使用json 4 程序启动,先登录或者…

http:(3):http响应头信息

HTTP 响应头信息 HTTP请求头提供了关于请求,响应或者其他的发送实体的信息。 在本章节中我们将具体来介绍HTTP响应头信息。 应答头 说明 Allow 服务器支持哪些请求方法(如GET、POST等)。 Content-Encoding 文档的编码(En…

php 强制刷新一次,强制浏览器使用PHP刷新所有内容

一个问题,特别是在创建AJAX应用程序时,是浏览器可以缓存页面的内容,以便在发出类似请求时,可以呈现相同的内容。要强制浏览器显示所需内容而不进行缓存,可以在页面中添加以下标题。header("HTTP/1.1 202 Accepted…

[Leedcode][JAVA][第1248题][统计「优美子数组][找规律]

【问题描述】 1248. 统计「优美子数组」 给你一个整数数组 nums 和一个整数 k。如果某个 连续 子数组中恰好有 k 个奇数数字,我们就认为这个子数组是「优美子数组」。请返回这个数组中「优美子数组」的数目。 示例 1:输入:nums [1,1,2,1,1]…

[ubuntu setting]Change system language

1.Open the software "语言支持". ​ 2.Then select "English" lauguage, an apply to whole system. ​ 3.reboot system. [end]转载于:https://www.cnblogs.com/lizhuohui/p/10274356.html

http:(4):http请求方法

HTTP 消息结构 HTTP是基于客户端/服务端(C/S)的架构模型,通过一个可靠的链接来交换信息,是一个无状态的请求/响应协议。 一个HTTP"客户端"是一个应用程序(Web浏览器或其他任何客户端)&#xff…

oracle控制文件全备失败,Oracle数据库案例整理-恢复数据库失败-主备机控制文件所在目录不同...

1.1 现象描述使用主机节点的控制文件在备机节点上进行恢复时失败。 主节点控制文件目录为:“/opt/HUAWEI/cgp/workshop/omu/database/control_file/f0s11”。控制文件为:-rwxrwxr-x 1 oracle oinstall 10043392 Apr 23 14:11 control01.ct…

[Leedcode][JAVA][第199题][二叉树的右视图][BFS][DFS][前中后序遍历]

【问题描述】199.二叉树的右视图 给定一棵二叉树&#xff0c;想象自己站在它的右侧&#xff0c;按照从顶部到底部的顺序&#xff0c;返回从右侧所能看到的节点值。示例:输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释:1 <---/ \ 2 3 <---\…

基于声音的击键信号识别

摘要 本文文章采用击键信号的短时能量及峰值片段的幅度及各个幅度对应的频率作为特征向量。采用声音搜集装置搜集敲击键盘产生的声音信号&#xff0c;并对声音信号进行巴特沃斯滤波方法进行滤波预处理&#xff1b;将上述经过滤波得到的信号减去环境背景信号&#xff0c;得到当…

http:(5):http状态码

HTTP状态码 当浏览者访问一个网页时&#xff0c;浏览者的浏览器会向网页所在服务器发出请求。当浏览器接收并显示网页前&#xff0c;此网页所在的服务器会返回一个包含HTTP状态码的信息头&#xff08;server header&#xff09;用以响应浏览器的请求。 HTTP状态码的英文为HTT…

oracle怎么从大字段中取节点,Oracle数据库 获取CLOB字段存储的xml格式字符串指定节点的值...

参照: Oracle存储过程中使用游标来批量解析CLOB字段里面的xml字符串背景:在写存储过程时,需要获取表单提交的信息。表单信息是以xml格式的字符串存储在colb类型的字段dataxml中&#xff0c;如何获取呢&#xff1f;参考百度内容&#xff0c;写一个function(函数)&#xff0c;参数…

[爬虫][python][入门][网页源码][百度图片][豆瓣TOP250]

Robots协议 查看爬取规则 遵守相关法律法规 Robots协议&#xff08;也称为爬虫协议、机器人协议等&#xff09;的全称是“网络爬虫排除标准”&#xff08;Robots Exclusion Protocol&#xff09;&#xff0c;网站通过Robots协议告诉爬虫哪些页面可以抓取&#xff0c;哪些页面不…

mysql(1):查找语句练习

1创建一个员工表 CREATE TABLE employees ( emp_no int(11) NOT NULL, birth_date date NOT NULL, first_name varchar(14) NOT NULL, last_name varchar(16) NOT NULL, gender char(1) NOT NULL, hire_date date NOT NULL, PRIMARY KEY (emp_no)); 2插入数据 insert into em…

CSS基础选择器(选择器的优先级),CSS样式块( 长度/颜色/显示方式/文本样式),盒模型组成,盒模型-block,盒模型布局...

CSS基础选择器 &#xff08;1&#xff09;id选择器: # 》 标签拥有 id"user" 属性 <style>#user {width: 200px;}</style><div id"user"></div> &#xff08;2&#xff09;( class ) 类选择器 : . 》 标签拥有 …