数据表 shopid, lot,lat,cot
查找N公里内平均cot大于W的商户
使用函数DIST(lot1,lat1,lot2,lat2)计算距离
SELECT shopid
FROM TABLE t1
GROUP BY shopid
HAVING W < AVG(
SELECT cot
FROM TABLE t2
WHERE DIST(t1.lot,t1.lat,t2.lot,t2.lat) < N
)
数据表 shopid, lot,lat,cot
查找N公里内平均cot大于W的商户
使用函数DIST(lot1,lat1,lot2,lat2)计算距离
SELECT shopid
FROM TABLE t1
GROUP BY shopid
HAVING W < AVG(
SELECT cot
FROM TABLE t2
WHERE DIST(t1.lot,t1.lat,t2.lot,t2.lat) < N
)
本文标题:SQL案例:查找N公里内活跃商户
本文链接:https://www.haomeiwen.com/subject/sdkbsftx.html
网友评论