declare @mNum int
set @mNum = 2
select top(10) cNum, name, vDay from
(
select fk_member as mNum, fk_cafe as cNum,
row_number() over(partition by fk_cafe order by visit_date_day desc) as rank,
visit_date_day as vDay
from member_visit
where fk_member =@mNum
) as mv
inner join cafe as cf
on mv.cNum = cf.sn
where rank = 1 and cast(vDay as datetime) > getdate()-7
order by vDay desc
댓글 영역