我试图框架的查询,但不知何故没有得到所需的结果,因此张贴。我是新来的Hive。如果事情很简单,我道歉。
源数据:
Ik - priority - ind1 - ind2 - date
1 - A - y - n - 2009/01/01
1 - B - n - y - 2019/02/09
1 - C - null - (empty)- 2018/05/07
2 - A - null - y - 2005/02/02
2 - B - null - y - 2006/05/05
2 - C - n - null - 2018/01/01
问题陈述
根据优先级和日期,我们需要为每个ik填充指示符值(ind1和ind2)。
输出表格式
ik,ind1,ind2
逻辑是
这里的分组将在ik场上进行。所以对于上面的数据集,在输出中将只有一条记录被填充。
如果对于相同的ik值,优先级为a,指示标志(ind1,ind2)为y值,则输出应填充为“y”。
但如果相同的ik,优先级是一个指示器,但没有值“y”(可能的值为null、n、空字符串)
然后将根据b c priority中的日期字段(order by date-latest record group by ik)选择latest indicator。
上述数据集的输出为
Ik - ind1 - ind2
1 - y - y
2 - n - y
这里ind1是max(ind1)。我能推导出。但无法导出ind2。
你能帮我创建查询吗?
1条答案
按热度按时间eivnm1vs1#
测试数据:http://demo.gethue.com/hue/editor?editor=293916
结果: