关于关联表的问题
假设有两张表,表1存放将某个区域分为小格的信息,字段x1,y1,x2,y2分别表示小格的最小和最大坐标;
表2存放很多经纬度信息;
先要求,将表2中的的数据与表1关联,即查询每个经纬度所属的小格ID(每个小格覆盖的区域不重复,因此每个经纬度信息对应一个小格ID)
详细的请看以下具体数据
--测试数据
create table t1(id int identity(1,1),name varchar(100),x1 numeric(9,3),y1 numeric(9,3),x2 numeric(9,3),y2 numeric(9,3))
go
declare @cntx int
declare @cnty int
set @cntx=0
set @cnty=0
--插入小格信息
while(@cntx<1000)
begin
set @cnty=0
while(@cnty<1000)
begin
insert into t1(name,x1,y1,x2,y2) values(left(newid(),5),@cntx*3,@cnty*3,@cntx*3+2.999,@cnty*3+2.999)
set @cnty=@cnty+1
end
set @cntx=@cntx+1
end
go
create table t2(area_id int identity(1,1),logi numeric(9,3),lat numeric(9,3))
go
--随机插入经纬度信息
declare @cntx int
set @cntx=0
while(@cntx<5000)
begin
insert into t2(logi,lat) values(abs(checksum(newid()))%3000,abs(checksum(newid()))%3000)
set @cntx=@cntx+1
end
go
--删除测试表
drop table t1
drop table t2
--我进行关联的方法
select * from t1 inner join t2 on logi between x1 and x2 and lat between y1 and y2
有没有更好更快的方法可以使用?
在相关字段建立索引可以提高查询的速度
现求更好的方法,或好的索引建立方案
请将方法和实现的效果、效率一并给出,谢谢
表2存放很多经纬度信息;
先要求,将表2中的的数据与表1关联,即查询每个经纬度所属的小格ID(每个小格覆盖的区域不重复,因此每个经纬度信息对应一个小格ID)
详细的请看以下具体数据
--测试数据
create table t1(id int identity(1,1),name varchar(100),x1 numeric(9,3),y1 numeric(9,3),x2 numeric(9,3),y2 numeric(9,3))
go
declare @cntx int
declare @cnty int
set @cntx=0
set @cnty=0
--插入小格信息
while(@cntx<1000)
begin
set @cnty=0
while(@cnty<1000)
begin
insert into t1(name,x1,y1,x2,y2) values(left(newid(),5),@cntx*3,@cnty*3,@cntx*3+2.999,@cnty*3+2.999)
set @cnty=@cnty+1
end
set @cntx=@cntx+1
end
go
create table t2(area_id int identity(1,1),logi numeric(9,3),lat numeric(9,3))
go
--随机插入经纬度信息
declare @cntx int
set @cntx=0
while(@cntx<5000)
begin
insert into t2(logi,lat) values(abs(checksum(newid()))%3000,abs(checksum(newid()))%3000)
set @cntx=@cntx+1
end
go
--删除测试表
drop table t1
drop table t2
--我进行关联的方法
select * from t1 inner join t2 on logi between x1 and x2 and lat between y1 and y2
有没有更好更快的方法可以使用?
在相关字段建立索引可以提高查询的速度
现求更好的方法,或好的索引建立方案
请将方法和实现的效果、效率一并给出,谢谢
...全文
相关推荐
hibernate 关联表问题
NULL 博文链接:https://lf6627926.iteye.com/blog/1176785
解决CodeIgniter 4中关联表的显示问题
摘要:本文介绍了在CodeIgniter 4中显示关联表数据的解决方案。通过医疗系统中的患者与血型表关联案例,分析了直接访问关联数据时出现的"Undefined array key"错误原因。解决方案是在控制器中使用JOIN查询关联数据,将血型描述作为新字段返回。文章提供了控制器和视图的代码示例,并强调了模型职责分离和LEFT JOIN的性能优势,帮助开发者正确处理CodeIgniter中的关联数据显示问题。(150字)
更新关联表的值
NULL 博文链接:https://airong.iteye.com/blog/356174
mysql删除关联表的实操方法
在本篇内容里我们给大家整理了关于mysql删除关联表的实操方法以及相关SQL语句,需要的朋友们学习下吧。
php基于数组函数实现关联表的编辑操作示例
主要介绍了php基于数组函数实现关联表的编辑操作,涉及php数组比较函数array_intersect与array_diff的相关使用技巧,需要的朋友可以参考下


疑难问题
