SELECT
*
FROM
(
SELECT
ROW_NUMBER() OVER (PARTITION BY Code ORDER BY Year DESC, Month DESC) AS row_number,
*
FROM
myTable
)
AS orderedTable
WHERE
row_number = 1
BEARBEITEN Und nun zu einer Version, die in MySQL FUNKTIONIERT...
SELECT
*
FROM
myTable
WHERE
Year * 12 + Month = (SELECT MAX(Year * 12 + Month) FROM myTable AS lookup WHERE Code = myTable.Code)
BEARBEITEN Nach dem Zugriff auf SQL kann ich bestätigen, dass dies schneller ist ...
WHERE
Year = (SELECT MAX(Year) FROM myTable AS lookup WHERE Code = myTable.Code)
AND Month = (SELECT MAX(Month) FROM myTable AS lookup WHERE Code = myTable.Code AND Year = myTable.Year)