表结构为id,name,path,lat,lng,time,lat为纬度,lng为经度,现在需要同时取得东西南北四个方向最大值记录行,即max(lat),min(lat),max(lng),min(lng)所对应的记录。如何写语句?

解决方案 »

  1.   

    select * from tb A
    where not exists (select 1 from tb A.lat<lat)
         or not exists (select 1 fro tb A.lat>lat)
         or not exists (select 1 fro tb A.lng<lng)
         or not exists (select 1 fro tb A.lng>lng)select * from A
    where lat=(select max(lat) from tb) 
        or lat=(select min(lat) from tb)
        or lng=(select max(lng) from tb)
        or lng=(select min(lng) from tb)
      

  2.   

    直接select max(lat),min(lat),max(lng),min(lng) from youtable;不行么