Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
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.

share|improve this question
2  
You can only have two values after BETWEEN. So x.num between PIXELX and PIXELX and DELTAX is not doing what you want. – Barmar Apr 16 at 21:36
Also the between at the end looks like it only has one argument. – Lawson Apr 16 at 21:39
2  
what do you mean by (Advanced) in your title? – rs. Apr 16 at 21:41
@rs.: presumably it was a thought that this query is advanced in some way – zerkms Apr 16 at 21:46
Well so far nobody was able to fix it so yes it is advanced (maybe a little too advanced for you 3) – user2288298 Apr 17 at 5:07
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.