In MySQL I used to be able to do something like:
SELECT Something1.ID, Something2.AverageValue FROM
(SELECT ID, Max(Date) FROM Table GROUP BY ID) Something1
LEFT JOIN
(SELECT ID, AverageValue FROM Table) Something2
ON Something1.ID = Something2.ID
So what I am trying to do is give me the most recent averagevalue, per ID
The syntax in SQL Server appears to be different and doesn’t allow me to do the nested SELECT statements?
This is the way you should do it in SQL Server. It makes “last/first/max/min/greatest-n-per group” easy as pie.
PARTITION BYkeyword here equals yourGROUP BYstatement, and theORDER BYhere would translate into theMAXaggregate function you used in MySQLUsing this would enable you to do some fancy stuff like: