sql - Get top three records from duplicate records having unique identity -
i'm using sql server 2008 r2. have table in management studio work
. want top 3 records each employee in table. table has primary key workid
, foreign key employeeid
. table sorted descending date. don’t need joins other tables. specific top 3 records current employeeid
. here example query.
select wtop.workid, wtop.employeeid work wtop wtop.employeeid in (select top 3 wsub.employeeid work wsub wsub.employeeid = wtop.employeeid order wsub.employeeid)
how using row_number.
something like
;with workvals ( select *, row_number() over(partition employeeid order [date] desc) rowid work ) select * workvals rowid <= 3
Comments
Post a Comment