1

我目前只是在寻找矩形形式,所以我试图让它在 phpmyadmin 上与 vanilla mysql 一起工作,我想要一个数据库,其中有多个区域可能相互重叠,每个区域都有“成本”每平方像素,因此您可以获取某个点的成本或测量整个区域的成本,同时忽略重叠的部分,您还可以获得数据库中现有总成本的平均值。

我想知道你们中的一个 mysql 兽医是否可以帮助我编写这样一个查询/数据库模式,我或多或少已经有了一些东西

select sum(c.cost) 
from (select x.num as x, y.num as y, max(priority) as maxpriority 
      from numbers x 
      cross join numbers y 
      join costs c 
      on x.num between c.x and c.x + c.deltax 
      and y.num between c.y + c.deltay 
      where x.value between PIXELX and PIXELX and DELTAX and 
      y.value between PIXELY and PIXELY and DELTAY 
      group by x.num, y.num) xyp
join costs c 
on xyp.x between c.x and c.x + c.deltax
and xyp.y between c.y + c.deltay
and xyp.maxpriority = c.priority 

这似乎是无效的并且充满了错误,也没有提到数据库模式。我花了几天时间尝试纠正它并使其工作,但它一直返回 null。

在此先感谢,我很感激。

以下是模式:这是数字:

Collation   Attributes  Null    Default Extra   Action
     1  num int(11)         No  None          Change      Drop    Browse distinct values     More

这是费用:

#   Name    Type    Collation   Attributes  Null    Default Extra   Action
 1  x   int(11)         No  None          Change      Drop    Browse distinct values     More
 2  y   int(11)         No  None          Change      Drop    Browse distinct values     More
 3  deltax  int(11)         No  None          Change      Drop    Browse distinct values     More
 4  deltay  int(11)         No  None          Change      Drop    Browse distinct values     More
 5  priority    int(11)         No  None          Change      Drop    Browse distinct values     More
4

1 回答 1

0

首先更正查询中的错误:

select sum(c.cost) 
from (select x.num as x, y.num as y, max(priority) as maxpriority 
      from numbers x 
      cross join numbers y 
      join costs c 
      on x.num between c.x and c.x + c.deltax 
      and y.num between c.y + c.deltay 
      where (x.value between PIXELX and PIXELX + DELTAX)   -- + instead of and
      and (y.value between PIXELY and PIXELY + DELTAY)     -- + instead of and
      group by x.num, y.num) xyp
join costs c 
on (xyp.x between c.x and c.x + c.deltax)
and (xyp.y between c.y and c.y + c.deltay)                 -- added c.y
and xyp.maxpriority = c.priority 

然后,如果您仍然没有得到所需的结果,请单独尝试内部查询以查看从中返回的内容。

于 2013-04-18T07:19:21.900 回答