hive常用命令和语句

 

desc  database/schema,table_name,view_name;

show create table xxx;

 

排序:

select * from  表名 order by  字段名;           #正序

select * from  表名 order by  字段名 desc;    #倒序

 

#命令主要是用来解决通过hdfs dfs -put或者hdfs api写入hive分区表的数据在hive中无法被查询到的问题。只需要运行MSCK REPAIR TABLE命令,hive就会去检测这个表在hdfs上的文件,把没有写入metastore的分区信息写入metastore。(即把hdfs路径里匹配的分区挂在表上)

msck repair table

https://blog.csdn.net/opensure/article/details/51323220

 

DDL见: D:\数据仓库\PART2\06 Hive优化\hive优化3

Union all(查)

 

2/ #查询司机表当前时间前6日当天分区里的这些字段

SELECT
a.dt,
a.city_id,
a.city_name,
a.product_id,
a.driver_id,
a.phone_number
FROM oride_dw.dim_oride_driver_base a    #表示司机表的别名
where a.dt=DATE_SUB(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),6) limit 10;#表示当前时间减去6天的值

unix_timestamp()是取系统时间函数

要查这个函数的结果,可以在beeline命令行输入select加函数查看:

select DATE_SUB(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),6) 

 

 

#取前一天的
SELECT
a.dt,
a.city_id,
a.city_name,
a.product_id,
a.driver_id,
a.phone_number
FROM oride_dw.dim_oride_driver_base a
where a.dt=DATE_SUB(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1) limit 10;

 

posted on 2019-08-30 20:31  锋锋2019  阅读(281)  评论(0编辑  收藏  举报

导航