sql:
SELECT u.user_id,
u.user_name,
u.mail_receive_time
FROM mail_user u,
mail_interior i
WHERE u.mail_id = i.mail_id
AND i.mail_creator = '8440'
AND u.mail_status <> 3
AND u.user_id <> i.mail_creator
AND u.mail_receive_time IS NOT NULL
ORDER BY u.mail_receive_time DESc;
前:
-
--去重复后
SELECT u.user_id,u.user_name,u.mail_receive_time
FROM
(SELECT a.*,
row_number() over(partition BY a.user_id order by a.mail_receive_time DESC)rn
FROM
(SELECT u.user_id,
mail_interior i
WHERE u.mail_id = i.mail_id
AND i.mail_creator = '8440'
AND u.mail_status <> 3
AND u.user_id <> i.mail_creator
AND u.mail_receive_time IS NOT NULL
) a
)u
WHERE rn=1
order by u.mail_receive_time desc;
原文链接:https://www.f2er.com/oracle/210839.html