Discussion: Documents select
Afficher un message
Vieux 02/04/2008, 14h45   #2
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Documents select

Try:

SELECT DocID, EmployeeID, DocumentType, ExpDate
FROM Documents AS A
WHERE ExpDate = (SELECT MAX(B.ExpDate)
FROM Documents AS B
WHERE B.EmployeeID = A.EmployeeID
AND B.DocumentType = A.DocumentType);

On SQL Server 2005:

SELECT DocID, EmployeeID, DocumentType, ExpDate
FROM (SELECT DocID, EmployeeID, DocumentType, ExpDate,
ROW_NUMBER() OVER(PARTITION BY EmployeeID, DocumentType
ORDER BY ExpDate DESC) AS
seq
FROM Documents) AS T
WHERE seq = 1;

HTH,

Plamen Ratchev
http://www.SQLStudio.com

  Réponse avec citation
 
Page generated in 0,05152 seconds with 9 queries