需求:
表justin中包含有justin_id和create_time字段,其中justin_id值不唯一,对于给定的日期值a,要求以justin_id为过滤条件返回表justin中创建日期最接近a的记录
解决方案:
采用分析函数
select * from
(select p.*, row_number() over(partition by justin_id order by a-create_time) rn from justin p )
where rn = 1;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15480802/viewspace-687021/
,如需转载,请注明出处,否则将追究法律责任。