<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9JNzFYMi5qcGcifQ==” alt =“在此处输入图像描述”>
请建议我,我已经尝试使用Oracle SQL中的分区和组,但是无法获得正确的查询
一个选项两次使用row_number()
:
select primary_key, id, created_date
from (
select
t.*,
row_number() over(partition by id, trunc(created_date) order by created_date asc) rn_asc,
row_number() over(partition by id, trunc(created_date) order by created_date desc) rn_desc
from mytable t
) t
where 1 in (rn_asc, rn_desc)