Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Gruppieren nach mit 2 unterschiedlichen Spalten in SQL Server

SELECT t1.id, t1.stat, t1.date
FROM testtable t1
JOIN (SELECT stat, MAX(date) date FROM testtable GROUP BY stat) t2 ON t1.stat = t2.stat AND t1.date = t2.date
GROUP BY stat