求助!如何实现以下查询?

jacobsan 2006-03-19 02:29:12
现有两张表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唯一

谢谢各位高人了~~~

...全文
78 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanshujian 2006-03-19
  • 打赏
  • 举报
回复
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
没有懂楼主的意思.你能给点测试数据吗?或者说的更加清楚点.
jacobsan 2006-03-19
  • 打赏
  • 举报
回复
有人知道吗?

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧