开发者

How would I order this SELECT statement in MySQL?

cursor.execute("SELE开发者_Python百科CT user_id FROM myapp_location WHERE\
       GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) < %s"\
       ,(user_utm_easting, user_utm_northing, 500));

This query selects users which are within 500 feet of the current user. How would I order people by the distance? (the glength). Nearby first, farthest last.

How would you change this query? THanks.


Here's one way

SELECT user_id
     , GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) as glength
  FROM myapp_location
HAVING glength < %s"
 ORDER BY glength desc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜