declare @t table (id int,j int,w int,title char(5))
insert into @t
select 1, 1, 2, 'test1' union
select 2, 2, 2, 'test2' union
select 3, 2, 3, 'test3' union
select 4, 4, 6, 'test4' union
select 5, 5, 2, 'test5'declare @p int
set @p = 2select a.id,power(b.j-a.j,2)+power(b.w-a.w,2) as length,a.title
from @t a,@t b
where a.id<>b.id and b.id=@p
/*
id length title
----------- ----------- -----
1 1 test1
3 1 test3
4 20 test4
5 9 test5(所影响的行数为 4 行)
*/
insert into @t
select 1, 1, 2, 'test1' union
select 2, 2, 2, 'test2' union
select 3, 2, 3, 'test3' union
select 4, 4, 6, 'test4' union
select 5, 5, 2, 'test5'declare @p int
set @p = 2select a.id,power(b.j-a.j,2)+power(b.w-a.w,2) as length,a.title
from @t a,@t b
where a.id<>b.id and b.id=@p
/*
id length title
----------- ----------- -----
1 1 test1
3 1 test3
4 20 test4
5 9 test5(所影响的行数为 4 行)
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货