挑选分组中top1


select * from
(

select *, ROW_NUMBER() over(partition by accountid order by opentime DESC) as rowNum
from ep_productopenhistory
WHERE accountid IN
(
SELECT accountid FROM dbo.ep_accountno
WHERE name IN
(
'1334760',
'1334761',
'1334762',
'1334763',
'1334764',
'1334765',
'1334766',
'1334767'
)
)

) ranked
where ranked.rowNum =1
order by ranked.accountid, ranked.opentime desc

posted @ 2013-10-09 11:26  深潭  阅读(239)  评论(0编辑  收藏  举报