Posted on 2012-04-04
I hope I explain this sufficiently. I am working on MS SQL Server 2008. I am looking to code an ANSI TSQL statement(s) that will do the following.
The table being accessed is defined as such (I have cut out non-relevant columns):
CREATE TABLE PSExtract.temp.RJZ_Temp
(KeyID INT NOT NULL
,DedupID INT NOT NULL
,DistinctID VARCHAR(61) NULL
,OSLevelID int NULL)
KeyID identifies a unique company,
DedupID defines a unique individual within a unique company
DistinctID = KeyID & ' - ' & DedupID
EmployeeCount is the total # of employees in a unique company (keyed on KeyID)
OSLevelID is the level of the employee in the food chain at the company, the lower the number, the higher the employee is at the company.
What I am trying to do is extract a list from this table, I want to only select 10,000 rows (the table has 150,000+ rows in it),
I want to select the companies that have the highest # of employees first
BUT I only want 3 employees per company
AND the 3 employees for each company are the highest level employees there (lowest OSLevelID value) (I realize that there may be employees of the same level who are not selected).
I am only 3 weeks into this job as a junior TSQL programmer so... don't assume I know anything.