Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Agrupar por com 2 colunas distintas no 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