oracle over(partition BY) 函数用法

前端之家收集整理的这篇文章主要介绍了oracle over(partition BY) 函数用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

猜你在找的Oracle相关文章