sql >> Base de Datos >  >> RDS >> Sqlserver

Agrupar por con 2 columnas distintas en 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