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 tuplecnsm_id
with has either type_cd=P
or type_cd=A
then the record should have max(timestamp)
.cnsm_id
doesn't have the type_cd='P'
then it should take the type_cd='A'
record with the largest timestampPlease 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.