1

嗨,伙计们,我目前有这张桌子

成员

**ID Position Latitude Longitute**

1   1       1.38086  103.749 
1   2       1.38086  103.749 
1   3       1.38086  103.749    
1   4       1.48086  103.949 
1   5       1.48086  103.949    
1   6       1.48086  103.949 
1   7       1.58086  103.749    

我目前正在使用select * from meber group by latitude,longitute order by position desc.

然而这将导致

**ID Position Latitude Longitute**
1   1       1.38086  103.749    
1   4       1.48086  103.949  
1   7       1.58086  103.749    

我希望结果显示使用分组依据的最高位置而不是最低位置。任何解决方案

4

3 回答 3

4

您必须使用子查询来确定每个组的最大位置,然后将其与您的选择连接以获得所需的记录:

SELECT *
FROM   meber NATURAL JOIN (
  SELECT   latitude,longitute,MAX(position) AS position
  FROM     meber
  GROUP BY latitude,longitute
) AS t

顺便说一句,英文单词拼写为“longitude”。

于 2012-06-07T07:36:37.957 回答
2
select MAX(position) position,latitude,longitute
from meber
group by latitude,longitute
于 2012-06-07T07:36:19.013 回答
0

子查询解决方案是最常见的一种。

我喜欢使用另一个,因为它不涉及子查询:

SELECT *
FROM member M
LEFT JOIN member N
    ON M.latitude = N.latitude
    AND M.longitute = N.longitute
    AND M.position < N.position
WHERE N.position IS NULL

请注意,为了获得最低位置,只需编写 M.position > N.position 即可。

于 2012-06-07T07:54:42.950 回答