1 distinct
select
cast(a.teach_plan_id as bigint) as teach_plan_id,
cast(nvl(teach_activity_num ,0) as int) as teach_activity_num,
cast(nvl(knowledge_num,0) as int) as knowledge_num
from
(select distinct id as teach_plan_id from ods.ods_teachingplan where dt='2021-02-20' and id is not null and del='N')a
left join
--教学活动数
(select teach_plan_id,count(distinct activity_id) as teach_activity_num from ods.ods_teachplan_content_item where dt='2021-02-20' and is_activity='true' and del='N' group by teach_plan_id)b on a.teach_plan_id=b.teach_plan_id
left join
--知识点数量统计
(select teach_plan_id,count(distinct knowledge_id) as knowledge_num from ods.ods_teachingplan_knowledge where dt='2021-02-20' and del='N' group by teach_plan_id)c on a.teach_plan_id= c.teach_plan_id
报错
java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row (tag=0) {"key":{"_col0":"3462800421816365056"},"value":null}
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: Attempting to overwrite nextKeyWritables[2]
解决办法:
删掉a表的distinct.(因a表的id其实是唯一的)
借鉴帖子:
https://blog.youkuaiyun.com/UncleMing5371/article/details/85236709?spm=1001.2014.3001.5506