直线上最近距离
需求:找到这些点中最近两个点之间的距离。
展示效果:
shortest |
---|
1 |
CREATE TABLE If Not Exists 33_point (x INT NOT NULL, UNIQUE INDEX x_UNIQUE (x ASC));
Truncate table 33_point;
insert into 33_point (x) values (-1);
insert into 33_point (x) values (0);
insert into 33_point (x) values (2);
最终sql:
select
min(abs(p1.x - p2.x)) as shortest
from
33_point p1
join
33_point p2
on
p1.x != p2.x