如何获取最近的儿童记录的日期?在 SQL 中,我试图获取最新的 MOPNOTES.MOPNOTEDATE。我还希望每个 MOPACTIVITY.MOPID 只记录一条记录。任何方向将不胜感激。
SELECT DISTINCT MOPACTIVITY.MOPID,
MOPNOTES.MOPNOTEDATE
FROM MOPUSER.MOPACTIVITY INNER JOIN MOPUSER.MOPNOTES ON MOPACTIVITY.MOPID=MOPNOTES.MOPID
WHERE MOPACTIVITY.MOPEND BETWEEN TRUNC(SYSDATE-1) + INTERVAL '12:00' HOUR TO MINUTE AND TRUNC(SYSDATE) + INTERVAL '9:00' HOUR TO MINUTE
AND UPPER(MOPACTIVITY.MOPSTATUS) = 'COMPLETE'
AND UPPER(MOPACTIVITY.MOPNOTIFICATIONSENT) LIKE '%TRUE%'
ORDER BY MOPACTIVITY.MOPID