现有两张表A(ID,Longitude,Latitude)
B(ID,x1,y1,x2,y2)
现要查询出满足条件Longitude>=x1 and Latitude>=y1 and Longitude<x2 and Latitude<y2的两表的ID,表A中每条记录对应表B中唯一的ID,即根据Longitude,Latitude判断属于表B中哪个ID
查询结果为A.ID,B.ID的对应表,A.ID唯一
谢谢各位高人了~~~
...全文
782打赏收藏
求助!如何实现以下查询?
现有两张表A(ID,Longitude,Latitude) B(ID,x1,y1,x2,y2) 现要查询出满足条件Longitude>=x1 and Latitude>=y1 and Longitude<x2 and Latitude<y2的两表的ID,表A中每条记录对应表B中唯一的ID,即根据Longitude,Latitude判断属于表B中哪个ID 查询结果为A.ID,B.ID的对应表,A.ID唯一 谢谢各位高人了~~~
If Exists(Select Name From Sysobjects Where Id = Object_Id(N'A'))
Drop Table A
Go
Create Table A
(ID Int,
Longitude Int,
Latitude Int)
Insert A
Select 1,100,100
Union All
Select 2,120,130
Union All
Select 3,130,140
Go
If Exists(Select Name From Sysobjects Where Id = Object_Id(N'B'))
Drop Table B
Go
Create Table B
(ID int,
x1 Int,
y1 Int,
x2 Int,
y2 Int)
Insert B
Select 1,10,10,10,10
Union All
Select 2,120,130,130,140
Union All
Select 3,130,140,160,170
Go
Select * From A
INNER Join
B
ON A.ID = B.ID
Where
Longitude>=x1 and Latitude>=y1 and Longitude<x2 and Latitude<y2
Go
没有懂楼主的意思.你能给点测试数据吗?或者说的更加清楚点.