我有一个相当长的查询,我一直在处理它抛出错误'#1052 - 字段列表中的列'lat'不明确'。我把它分成几部分,每个部分似乎都工作正常,但是当我一次运行它时,我得到了这个错误。这是查询:
SELECT lesson_requests_global_2.student_name,
(3959 * ACOS(COS(RADIANS(30.096595)) * COS(RADIANS(lat)) * COS(RADIANS(lng) - RADIANS(- 81.718983)) + SIN(RADIANS(30.096595)) * SIN(RADIANS(lat)))) AS distance,
lesson_requests_vendor.user_purchased
FROM lesson_requests_global_2
INNER JOIN
( SELECT student_name,
MAX(request_date) AS max_request_date
FROM lesson_requests_global_2
WHERE ( 3959 * ACOS(COS(RADIANS(30.096595)) * COS(RADIANS(lat)) * COS(RADIANS(lng) - RADIANS(- 81.718983)) + SIN(RADIANS(30.096595)) * SIN(RADIANS(lat))) ) < 30
GROUP BY student_name ) AS recent_student_lesson_request ON lesson_requests_global_2.student_name = recent_student_lesson_request.student_name
AND lesson_requests_global_2.request_date = recent_student_lesson_request.max_request_date
LEFT JOIN lesson_requests_vendor ON v.user_purchased = lesson_requests_global_2.student_name
WHERE lesson_requests_vendor.user_purchased <> 'bob jones'
AND distance < 30
ORDER BY distance LIMIT 0 , 20
请注意,长 COS/RADIANS 的东西看起来很复杂,但它是找到一英里半径的距离。我认为它以某种方式认为这些公式中的“纬度”以某种方式在列列表中?
在此先感谢您的帮助!