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

Come selezionare una riga massima per ogni gruppo in SQL

prova invece questa query,

  WITH OrderedOrders AS
  (
     SELECT country,grpid,value,ROW_NUMBER() OVER(PARTITION BY country ORDER BY   country,value DESC) AS 'RowNumber' 
     FROM test1
  ) 
 select * from  OrderedOrders
 where RowNumber =1