[英]Hive query for a specific scenario
Suppose my data is like below:假设我的数据如下:
And the output should be as below:输出应如下所示:
The Conditions are:条件是:
cnsm_id
consists Type_cd='P'
then I need only that tuple如果cnsm_id
包含Type_cd='P'
那么我只需要那个元组cnsm_id
with has either type_cd=P
or type_cd=A
then the record should have max(timestamp)
.如果cnsm_id
具有type_cd=P
或type_cd=A
则记录应该有max(timestamp)
。cnsm_id
doesn't have the type_cd='P'
then it should take the type_cd='A'
record with the largest timestamp如果cnsm_id
没有type_cd='P'
那么它应该采用具有最大时间戳的type_cd='A'
记录Please who knew the answer could help me in solving this query?请问谁知道答案可以帮助我解决这个查询?
SELECT
CNSM_ID,
MAX(t),
TYPE_CD
FROM(
SELECT
CNSM_ID,
MAX(TIMESTAMP) AS t,
type
FROM
TBL_NAME
GROUP BY
CNSM_ID,
TYPE_CD
ORDER BY t DESC) AS TBL_NAME1
GROUP BY CNSM_ID;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.