日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle 外部表 时间戳,Hive建立外部表与时间戳转换(含建dual表,修改列名,row_number() 函数等)... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

建外部表,之前hadoop職位統(tǒng)計(jì)就是這么做的

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先建好這個(gè)文件夾,并上傳好數(shù)據(jù)

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';

將日期轉(zhuǎn)化為時(shí)間戳

hive> select unix_timestamp(time,'yyyyMMddHH') from tctest;利用上面的函數(shù)+CTAS語(yǔ)句創(chuàng)建一個(gè)含時(shí)間戳的表

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表

因?yàn)镠ive里沒(méi)有自帶dual表,所以我們要自己建一個(gè)

hive> create table dual(dummy string);#之后建一個(gè)dual.txt里面寫個(gè)值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)

將時(shí)間戳轉(zhuǎn)化為日期

hive> select from_unixtime(1418831999) from dual;

OK

2014-12-17 23:59:59

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

查看表結(jié)構(gòu)

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)修改列名,注意那是反引號(hào)

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

OK

Time taken: 0.172 seconds

將hive表中內(nèi)容導(dǎo)到本地

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

開始的想法奉上(當(dāng)時(shí)沒(méi)有理解題意,想的也比較簡(jiǎn)單)

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;#查看表的前五行數(shù)據(jù)

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;

改進(jìn)一下

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

或者,更直接一點(diǎn)

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

或者,改進(jìn)一點(diǎn),用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;再改進(jìn)一點(diǎn)

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);

下面來(lái)自:http://jingyan.baidu.com/article/9989c74604a644f648ecfef3.html

簡(jiǎn)單的說(shuō)row_number()從1開始,為每一條分組記錄返回一個(gè)數(shù)字,這里的ROW_NUMBER() OVER (ORDER BY xlh DESC) 是先把xlh列降序,再為降序以后的沒(méi)條xlh記錄返回一個(gè)序號(hào)。

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

根據(jù)部門分組,顯示每個(gè)部門的工資等級(jí)

總結(jié)

以上是生活随笔為你收集整理的oracle 外部表 时间戳,Hive建立外部表与时间戳转换(含建dual表,修改列名,row_number() 函数等)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。