数据库学习纪要(五):hive-5

来源:互联网 发布:两心之外无人知意思 编辑:程序博客网 时间:2024/05/21 04:17
三、HIVEQL命令
3.1.基础操作

假设表格shield_fm_feature_item_ctr 的格式是:owner (string), key (string), value (int), day (bigint);

1)select * from shield_fm_feature_item_ctr; // 查找数据

2)select * from shield_fm_feature_item_ctr limit 10; // 查找10行数据

3)select * from shield_fm_feature_item_ctr where day=20160301; //查询 day=20160301 的数据

4)select * from shield_fm_feature_item_ctr where day >= 20160301 and day<=20160302;//查询 day>=20160301 并且 day<=20160302 的数据

5)select * from shield_fm_feature_item_ctr where day = 20160301 or day =20160302;//查询 day=20160301 或者 day=20160302 的数据

6)select * from shield_fm_feature_item_ctr where day=20160301 order by value; // 按照value 的值增序排列

7)select * from shield_fm_feature_item_ctr where day=20160301 order by value desc;// 按照 value 的值降序排列

8)insert [overwrite] into table shield_fm_feature_item_ctr partition (day=20160301) values (‘20032′,’key_20032’,1.0)// 不使用overwrite是往表格里追加一条数据,如果使用overwrite就是覆盖整个表格。

3.2.高级操作

1)select * from shield_fm_feature_item_ctr where day between 20160301 and 20160302; //查询表格中从20160301到20160302的数据

2)JOIN 操作:非常重要的概念

--》 inner join: 在表格中至少存在一个匹配时,inner join 的关键字返回行;注:inner join 和 join 是相同的。

--》 left join: 会从左边的表格返回所有的行,即使在右边的表格中没有匹配的行。

--》 right join:会从右边的表格返回所有的行,即使在左边的表格中没有匹配的行。

--》 full join:只要其中的一张表存在匹配,full join 就会返回行。在某些数据库中,full join 也称作 full outer join。

--》 union:用于合并两个或者多个 select 语句的结果集。

--》 is NULL & is not NULL:来判断某个字段是否是空集。

四、函数
4.1.聚合函数
group by:通常和聚合函数一起使用,根据一个或者多个列对结果进行分组

常见的聚合函数有:
AVG:返回数列值的平均值

COUNT:返回一列值的数目

MAX/MIN:返回一列值的最大值/最小值

SUM:返回数列值的总和


4.2.数值函数
MOD(x,y):取模 x%y

ln(double a):返回给定数值的自然对数

power(double a, double b):返回某数的乘幂

sqrt(double a):开平方

sin/cos/asin/acos:三角函数

4.3.字符串函数

字符串函数(替换,拼接,逆序等)

4.4.日期函数
进行unix的时间转换等
原创粉丝点击