select t1.date,
t1.id,
t3.saleCount,
(select sum(tb3.saleCount) from table3 tb3
where tb3.id in (select t11.id from table1 t11,table2 t22 where 计算经纬度的条件 and t11.dates = t1.dates and t11.pro = t1.pro and t11.city = t1.city and t11.id <> t1.id and t22.id = t11.id))
from table1 t1,table2 t2,table3 t3
where t3.id = t1.id and t2.id = t1.id
简单的想了一下,先看看把,不一定对
SELECT t2.id,t2.经度,t2.纬度,t3.销量 FROM t2,t3 WHERE t2.id = t3.id GROUP BY t2.id
SELECT t3.日期, t2.id,,sum(t3.销量) FROM t2,t3 WHERE t2.id = t3.id and t2.经度<x数值 and t2.维度<y数值 GROUP BY t3.日期,t2.id;
你这要求的结果有问题吧,每个id三公里内所有id的总销量,这两个id都分别对应哪个表的id
select a.日期,a.id,sum(d.销量)
from
(select * from table1 where 类型='A') a
join table2 b --取出A类型的id经纬度
on a.id=b.id
join table2 c --关联所有id经纬度,计算距离,where 中过滤
on 1=1
join table3 d --关联的id销量用于求和
on c.id=d.id
where
(6371 * acos(cos(radians(b.纬度)) * cos(radians(c.纬度)) * cos(radians(b.经度) - radians(c.经度)) +
sin(radians(b.纬度)) * sin(radians(c.纬度))))<10
group by a.日期,a.id