Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
SELECT MAX(counter) AS Expr1, qusId, empNameFROM empCounter AS empCounter_1GROUP BY qusIdthis query is wrong becuse empName dosn't in the group by clusevbut i want to display only the empName of the maxmum counter for each qusIdhow can i do this zezo
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2008-06-22 : 10:27:44
SELECT empName, counterFROM (SELECT empName, counter, ROW_NUMBER() OVER (PARTITION BY qusID ORDER BY counter DESC) AS RecIDFROM empCounter) AS fWHERE RecID = 1E 12°55'05.25"N 56°04'39.16"
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-06-22 : 12:53:04
or
SELECT e.qusId,b.empName,b.counterFROM empcounter eCROSS APPLY (SELECT TOP 1 empName,counter FROM empcounter WHERE qusId=e.qusId ORDER BY counter DESC)b