分组后获取分组中对应的消息
主体思路,先分组,然后获取关键数据,进行级联或利用EXISTS关键字
SELECT * FROM (
SELECT B.*
FROM
(SELECT ACCEPTNO,
TASK_ID,
MAX(TIME_MARKER) AS MTM
FROM KK WHERE TIME_MARKER > 5 AND FILD_COUNT < 5
GROUP BY ACCEPTNO,
TASK_ID) A
LEFT JOIN (SELECT * FROM KK WHERE TIME_MARKER > 5 AND FILD_COUNT < 5) B
ON A.ACCEPTNO = B.ACCEPTNO
AND A.TASK_ID = B.TASK_ID
AND A.MTM = B.TIME_MARKER
) T WHERE T.status = 'U';
SELECT *
FROM KK
WHERE TIME_MARKER > 5 AND FILD_COUNT < 5
AND EXISTS (
SELECT 1
FROM (
SELECT ACCEPTNO, TASK_ID, MAX(TIME_MARKER) AS MTM
FROM KK
WHERE TIME_MARKER > 5 AND FILD_COUNT < 5
GROUP BY ACCEPTNO, TASK_ID
) T
WHERE T.ACCEPTNO = KK.ACCEPTNO AND T.TASK_ID = KK.TASK_ID AND T.MTM = KK.TIME_MARKER
) AND STATUS = 'U';
标签:TASK,ACCEPTNO,TIME,关键,sql,MARKER,ID,SELECT
From: https://www.cnblogs.com/caoxuekun/p/17555147.html