MySQL query returning null

2020-05-07 10:25发布

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.num between PIXELX and PIXELX and DELTAX and
            y.num 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

I am trying to get the "cost" of a selected area in 2d which is populated by different area sizes with different costs overlapping each other by priority. (if an area is below another area it is ignored)

This is numbers:

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

This is costs:

#   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

What am I missing? The code is probably riddled with errors.

标签: mysql
0条回答
登录 后发表回答