gpt4 book ai didi

mysql - 数据库中最近的自由坐标

转载 作者:可可西里 更新时间:2023-11-01 08:04:49 25 4
gpt4 key购买 nike

我的数据库中有 X 和 Z 坐标。坐标是整数。

每个坐标都大于或等于0。

我需要将最近的自由(不在数据库中)坐标设为 0;0,但我不想将一个坐标限制为指定的数字。

同样,我不想在数据库中获取最近的坐标,我想获取最近的免费坐标。

这是我自己做的。但它只告诉我坐标方 block 中的可用空间在哪里(受数据库中最大 X 和最大 Z 坐标的限制)。

问题是我无法从中选择自由坐标。我只得到自由坐标的距离,而不是那个坐标。

SELECT distance
FROM (
SELECT (x+z) AS distance,COUNT(owner) AS count
FROM coordinates
GROUP BY x+z ASC
) AS coor
WHERE coor.distance != coor.count-1

最佳答案

我会尝试这样的事情:

select x, z
from (
select x, z+1 as z from coordinates union all
select x+1, z from coordinates union all
select x+1, z+1 from coordinates union all
select 0, 0
) as q
where
concat(x,'_',z) not in (select concat(x,'_',z) from coordinates)
order by (x+z) asc
limit 1

关于mysql - 数据库中最近的自由坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34828886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com