适当的数据库架构

时间:2013-04-16 12:06:35

标签: mysql phpmyadmin mysqli

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 and 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

在寻找由每个区域具有不同成本的区域填充的数据库中的两点之间的“成本”时,我得到了这个答案。我一直试图让这个工作,同时找出数据库架构,目前我正在#1054 - Unknown column 'x.value' in 'where clause'

Name    Type    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

作为成本。一直试图弄清楚这一点非常感谢任何人指点。

编辑:好的,它现在不会抛出错误,但它会返回null而不是选定区域内的成本。

1 个答案:

答案 0 :(得分:2)

您的numbers表没有名为value的列,并且您正在尝试引用不存在的列,因此您会收到错误消息。您当前的代码:

where x.value between PIXELX and PIXELX and DELTAX and

我猜您想要使用num代替:

where x.num between PIXELX and PIXELX and DELTAX and
      y.num between PIXELY and PIXELY and DELTAY