openvk/Web/Models/sql/get-nearest-posts.tsql

12 lines
300 B
Text
Raw Normal View History

2023-08-03 23:30:01 +03:00
SELECT *,
SQRT(
POW(69.1 * (? - geo_lat), 2) +
POW(69.1 * (? - geo_lon) * COS(RADIANS(geo_lat)), 2)
) AS distance
FROM posts
2023-08-03 23:30:01 +03:00
WHERE id <> ?
AND FROM_UNIXTIME(created) >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
2023-08-03 23:30:01 +03:00
HAVING distance < 1 AND distance IS NOT NULL
ORDER BY distance
LIMIT 25;