Wenn SQL Server 2005+
;WITH m AS
(
SELECT Partnum, Formula, RevisionNum,
rn = ROW_NUMBER() OVER (PARTITION BY PartNum ORDER BY
CASE WHEN RevisionNum ='New' THEN 1 ELSE 2 END)
FROM dbo.Material
)
SELECT p.PartNum, m.Formula, m.RevisionNum
FROM dbo.Parts AS p
INNER JOIN m ON p.PartNum = m.PartNum
WHERE m.rn = 1;
Obwohl neugierig, was tun Sie, wenn es mehr als 26 Revisionen gibt (z. B. was nach Z
kommt )?