Second highest value

n90

Registered User.
Local time
Today, 09:20
Joined
Dec 6, 2013
Messages
18
So I have a table that has basically the history of Statuses of Job Numbers until the status is set to closed(this includes information like date/who changed the status etc).

And what I am trying to do is run a query that will group by Job Number and have the second highest date, which will in turn allow me to show when the Job Status was last changed and who changed it.

But this is looking like its more difficult than I thought.
 
try this psuedocode

SELECT DISTINCT JobNumber, JobDate, JobChangedBy, (SELECT Max(JobDate) FROM tblStatus as Tmp where JobNumber=tblStatus.JobNumber AND JobDate<tblStatus.jobDate) as LastDateChanged FROM tblStatus
 
try this psuedocode

SELECT DISTINCT JobNumber, JobDate, JobChangedBy, (SELECT Max(JobDate) FROM tblStatus as Tmp where JobNumber=tblStatus.JobNumber AND JobDate<tblStatus.jobDate) as LastDateChanged FROM tblStatus

This works however it is giving me the second highest date and ALL previous ones. I just need the second highest date.
 
Can you post some examples of your data and the result you want to see, I don't understand what it is your require - I thought I did:D
 

Users who are viewing this thread

Back
Top Bottom