| Author |
Topic |
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-10-05 : 11:29:07
|
| I would like to get a Maximum Rate per Employee Number. I have written the following:SELECTSheet1.EmplNum,Sheet1.Rate,Sheet1.HireDate,Sheet1.PayType,Sheet1.RateEvent,Sheet1.Begin_Date,Sheet1.employeeFROM Sheet1Inner Join(SelectMax(Sheet1.Rate AS "MaxRate"ANDSheet1.EmplNum Count(*))GROUP BYSheet1.EmplNumON Sheet1.EmplNum=Sheet1.EmplNumANDSheet1.Rate=Sheet1.MaxRateAny assistance you could provice would be appreciated.Thank you,Mary |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-05 : 11:37:39
|
It would be nice to have the table structure, example data and wanted result. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-10-05 : 11:46:14
|
| The table structure consists of the following columns:EmplNum,Rate,HireDate,PayType,RateEvent,Begin_Date,employeeThe emplnum (employee number) is repeated in the table many times because the pay rate (Rate Column) has changed several times per employee number. What I need to find is the maximum pay rate per employee number. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-05 : 11:54:35
|
This?SELECTs1.EmplNum,s1.Rate,s1.HireDate,s1.PayType,s1.RateEvent,s1.Begin_Date,s1.employeeFROM Sheet1 s1Inner Join(SelectMax(Rate) AS MaxRate,EmplNumFROM Sheet1GROUP BY EmplNum)dtON s1.EmplNum=dt.EmplNumAND s1.Rate=dt.MaxRate No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-05 : 12:24:07
|
if 2005 thenSELECT s1.EmplNum,s1.Rate,s1.HireDate,s1.PayType,s1.RateEvent,s1.Begin_Date,s1.employeeFROM(SELECT *,ROW_NUMBER() OVER (PARTITION BY EmplNum ORDER BY Rate DESC) AS SeqFROM Sheet1)s1WHERE s1.Seq=1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-10-05 : 12:24:25
|
| This works but I have a couple of questions just so I can understand. I see the error I made in syntax, but in the FROM Line:Sheet1 s1Did this create an alias for Sheet1?Later in the Select statement at the end )dtWhat is dt? Is this an alias for the sub query? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-05 : 12:26:51
|
quote: Originally posted by meberg66219 This works but I have a couple of questions just so I can understand. I see the error I made in syntax, but in the FROM Line:Sheet1 s1Did this create an alias for Sheet1?Later in the Select statement at the end )dtWhat is dt? Is this an alias for the sub query?
yeah. Both are aliases used one for Sheet1 table and other for derived table------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
meberg66219
Yak Posting Veteran
65 Posts |
Posted - 2010-10-05 : 14:03:05
|
| Thank you very much for the assistance! |
 |
|
|
|