2
place(pid, name, type, lat, lng, deleted)
I want to select count of places, grouping them by their type and having a distance of < 10 KM from a particular lat, lng
查詢:
SELECT count(p.type) as count
FROM (place as p)
where p.deleted != 1
and p.pid in
(
select p2.pid,
IFNULL(acos(sin((18.5236 *pi()/180)) * sin((p2.lat*pi()/180))+cos((18.5236 *pi()/180)) * cos((p2.lat *pi()/180)) * cos(((73.8478 - p2.lng)*pi()/180))) * 6371.009, 0) AS distance
from place p2
having `distance` < 10
)
group by p.type;
錯誤:
Operand should contain 1 column(s)
那是因爲我選擇2列即在子select查詢PID和距離。但是,如果不使用第二個選擇列,我如何計算距離。
您IFNULL(ACOS ...)<10添加到WHERE條件在內部查詢和SELECT子句中刪除。 – wxyz
@StuartLC MySql –
你的子查詢應該只返回一列。 – Jade