hive:group by ,having 和order by等使用情况;hive分区中的select *


hive上 查询

hive> select * from app_data_stats_historical where os='1' group by dt limit 100;

出现结果如下:

2014-01-01
2014-01-06
2014-01-13
2014-01-20
2014-01-27
2014-02-01
2014-02-03
2014-02-04
2014-02-07
2014-02-10
2014-02-14
2014-02-17
2014-02-24

(只返回了一列日期。说明* 不起作用。

不过这样,可以查看总共哪些日期,有效,存在数据)

加上having命令:

select * from app_data_stats_historical where os='1' group by dt having dt>' limit 1002014-02-01' limit 100;

2014-02-03
2014-02-04
2014-02-07
2014-02-10
2014-02-14
2014-02-17
2014-02-24

(可以用日期进行比较。)

 

hive> select * from app_data_stats_historical where os='1' order by dt desc limit 100;

字段是全部返回的。降序。

 

 

 

hive存在分区partition后, 用select * 可以查出所有字段值,包括分区字段值。

但是用 select * > localdata.txt,导入到本地时,文件里第一行的属性字段不会出现分区字段,而记录中出现分区字段值存在,总结:分区字段名没有,值存在。

相关内容