Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Top n rows per group
Thu, Sep 13 2012 9:56 PMPermanent Link

ClockOn

how do you get the top 5 rows per group?

I basically have a list of employees with 2 different site numbers and and i want the top x number of employees for each site, i just cant figure this one out, in this list ive shown top 2...

NAME   ID      SITENO
Bob      100    001
Fred      4       002
Jack      41     002
Jill        11      001
Sam      23     001
Sarah    24     002
Tina       21     002


NAME   ID      SITENO
Bob      100    001
Jill        11      001
Fred      4       002
Jack      41     002
Sun, Sep 16 2012 5:36 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

ClockOn Smiley

You can do it with a temporary table and a script:

SELECT * INTO TmpTable FROM EmpTable WHERE SiteNo = '001' ORDER BY Name TOP 5 ;
INSERT INTO TmpTable SELECT * FROM EmpTable WHERE SiteNo = '002' ORDER BY Name TOP 5 ;
SELECT * FROM TmpTable ;


--
Fernando Dias
[Team Elevate]
Sun, Sep 16 2012 7:50 PMPermanent Link

ClockOn

Hi Fernando Smile

thanks for the reply but i was hoping for something a bit more generic as in most instances I do not know the SiteNo. I was thinking of trying to get a running count by location of how many shifts there are and removing anything > 50 but Ive had no luck getting that running.
Sun, Sep 16 2012 8:27 PMPermanent Link

ClockOn

I meant employees not shifts, lol...
Mon, Sep 17 2012 4:16 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

ClockOn


I think John Hay has posted a solution to this sort of problem. I can't remember which post it was but try searching for his name in these newsgroups.

Roy Lambert [Team Elevate]
Mon, Sep 17 2012 7:39 PMPermanent Link

ClockOn

Image