请问这个sql该怎么写?
id logid counts
1 jeff 0
2 jeff 10
3 jeff 0
4 face 8
5 face 0
6 jeff 1
7 jeff 0
8 face 7
9 jeff 0
10 jeff 0
11 jeff 0
12 xixi 6
13 xixi 2
14 xixi 11
如何用最简单的sql来查询不同logid,counts最大的记录,并按倒序排列,结果如:
14 xixi 11
2 jeff 10
4 face 8
------解决方案--------------------Select
*
From
TableName A
Where
Not Exists(Select counts From TableName Where logid = A.logid And counts > A.counts)
Order By
counts Desc
------解决方案--------------------select max(id) as 'id ',logid,max(counts) as 'counts '
from 表
group by logid
order by max(id) desc,max(counts) desc
------解决方案--------------------Select
*
From
TableName A
Where
counts = (Select Max(counts) From TableName Where logid = A.logid)
Order By
counts Desc
------解决方案--------------------Select
A.*
From
TableName A
Inner Join
(Select logid, Max(counts) As counts From TableName Group By logid) B