我正在为我的项目编写一个有点复杂的查询我有两个表,如下所示 test, test_Av
测试:
CREATE table test(id int not null, title varchar(50), place
varchar(20), postcode varchar(20), primary key(id));
INSERT INTO test VALUES(1,'test','','91982');
INSERT INTO test VALUES(2,'test','','91982');
INSERT INTO test VALUES(3,'test','','91982');
INSERT INTO test VALUES(4,'test','','91982');
INSERT INTO test VALUES(5,'test','','91982');
测试_AV
CREATE table test_AV(id int not null, testid int, name varchar(25),
stringvalue varchar(25) ,primary key(id));
INSERT INTO test_AV VALUES(1,1,'latitude','16.15074');
INSERT INTO test_AV VALUES(2,1,'longitude', '-22.74426');
INSERT INTO test_AV VALUES(3,2,'latitude','16.13725');
INSERT INTO test_AV VALUES(4,2,'longitude', '-22.85822');
INSERT INTO test_AV VALUES(5,3,'latitude','14.85633');
INSERT INTO test_AV VALUES(6,3,'longitude', '-24.72379');
INSERT INTO test_AV VALUES(7,4,'latitude','14.86949');
INSERT INTO test_AV VALUES(8,4,'longitude', '-24.70150');
INSERT INTO test_AV VALUES(9,5,'latitude','15.03118');
INSERT INTO test_AV VALUES(10,5,'longitude', '-24.32523');
test_AV 表中的 testid 是外键
我需要从给定的“纬度”和“经度”找到半径 100 公里的结果来实现这一点我写了这样的查询
select * from ( SELECT id,
title,
((ACOS(
SIN(16.15074 * 3.141592653 / 180)
* SIN((SELECT stringvalue from test_AV WHERE name='latitude')
* 3.141592653 / 180)
+ COS(16.15074 * 3.141592653 / 180)
* COS((SELECT stringvalue from test_AV WHERE name='latitude')
* 3.141592653 / 180)
* COS((-22.74426 - (SELECT stringvalue from test_AV WHERE name='longitude'))
* 3.141592653 /180))*6373)) AS distance FROM
test ) t where distance <= 100
代替子查询中的子查询,我需要 test_AV 表中的所有纬度和经度值,当我写这个时,它是说子查询是说子查询返回多行
我怎样才能做到这一点?