Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Raggruppa per con 2 colonne distinte 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