1 回答

TA貢獻1804條經驗 獲得超3個贊
我在您的查詢中主要發現了兩個問題:
加入
t1.ID
導致出現以下錯誤 MySQL:“#1054 - 'on 子句'中的未知列 't1.ID'”,即使我不確定原因;您的子查詢返回 2 列(
latitude
和longitude
),這會導致錯誤“#1241 - 操作數應包含 1 列”
我的建議如下:
SELECT wp_posts.*,
(POW(69.1 * (stores.latitude - $lat), 2) +
POW(69.1 * ($lon - stores.longitude) * COS(stores.latitude / 57.3), 2)) AS distance
FROM wp_posts
LEFT JOIN wp_product_store_relations ps ON ps.product_id = wp_posts.ID
LEFT JOIN wp_stores stores USING (store_id)
WHERE wp_posts.post_type = "product"
HAVING distance < POW(50, 2)
ORDER BY distance ASC;
注意:我想我的查詢可以通過加入wp_stores僅包含相關商店(具有產品和距離約束)而不是整個表的子集來優化,但沒有進一步調查。
編輯:刪除wp_posts表上的別名。
- 1 回答
- 0 關注
- 121 瀏覽
添加回答
舉報