hive 同一个表不同分区的数据求和
2017-05-12 16:53
246 查看
业务表如下:
业务需求:不同dt分区下的字段count的值需要累加:
hive> desc sc_kekaoxing; OK id string 可靠小表id car_id string car表id month string 月份 name string 可靠名称父级 count string 可靠数量 dt string dp string # Partition Information # col_name data_type comment dt string dp string Time taken: 0.128 seconds, Fetched: 13 row(s)
hive> select * from sc_kekaoxing limit 5; OK 1 10 201612 车身外观 5 201612 qiche 1 11 201612 车身外观 6 201612 qiche 1 12 201612 车身外观 7 201612 qiche 1 13 201612 车身外观 2 201612 qiche 1 14 201612 车身外观 17 201612 qiche Time taken: 0.386 seconds, Fetched: 5 row(s)
业务需求:不同dt分区下的字段count的值需要累加:
INSERT OVERWRITE local directory '/tmp/t01' row format delimited fields terminated by '\t' select if(aa.id is null,bb.id,aa.id), if(aa.car_id is null,bb.car_id,aa.car_id), '201702', if(aa.name is null,bb.name,aa.name), case when aa.count is not null and bb.count is not null then aa.count+bb.count when aa.count is null and bb.count is not null then bb.count when aa.count is not null and bb.count is null then aa.count else 0 end from (select * from sc_kekaoxing where dt='201612') aa full outer join (select * from sc_kekaoxing where dt='201702') bb on aa.id=bb.id and aa.car_id=bb.car_id and aa.name=bb.name;
相关文章推荐
- mapreduce不同类型的数据分到同一个分区是否会影响输出结果
- 一个DataGrid多次绑定不同数据的时候的用法
- 取不同分类下,每分类前N条数据的一个sql
- 打印同样一个数据,竟然出现不同的结果,解决方法。
- 妙用union和enum实现只有一个数据成员的类可存储不同的类型
- sqlserver 两个数据库中表的结构不同,如何把一个表中的数据导入到另一个表中
- 一个DataGrid多次绑定不同数据的时候我的用法
- 移动硬盘一个分区“数据循环冗余错误”要求格式化解决方法
- 同一个表中查询不同的数据,执行时间相差很远,是什么原因?
- 多张表数据填充到一个表中,或不同条件数据在同一张表或多张表中填补一个对象后,以不同条件分别填充不同对象。
- 打印同样一个数据,竟然出现不同的结果,解决方法。
- 巧用Bulk Copy将大量的数据复制到数据库(对同一个数据的表或不同一个数据库的表都行)
- oracle中不同用户下的表复制 或 将一个表中的数据复制到另一个表中
- ghost系统成一个分区后的数据恢复
- Hive中的数据分区
- 一个使用泛型堆栈模块创建的两个容纳不同类型数据的实例
- 同一个服务器,不同表数据的复制
- 同一个用户在不同页面共享数据的常用方法
- ORACLE同一个数据库下不同表结构之间的数据导入
- 同一个表中取出不同类别中的第一条数据