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
精彩评论