> If I understand it right you'll definitely need a correlated subquery. > You need one query to calculate the max() of the 257(0-256?) values. > There must be some way to define which values should be used > in that calculation for a specific piece (the distance). Is > the distance geometric and calculated from x,y? > > In pseudo code something like this: > > select piece, ( sub query to calculate max where distance > from desired_piece < 256 ) from blah where piece = desired_piece
Explain what you mean by "correlated subquery." Like I said in the original post, I need help to modify this exact query: SELECT qi,ri,(drl- (qi - :qi) ) as drl,MAX(score - ((ri - :ri) * :match)) AS scr FROM results_1 WHERE (qi - ri) = (:qi - :ri) AND (qi >= :qi) AND (ri >= :ri) AND (qi < :qi + 256) AND (ri < :ri + 256) AND (drl > qi - :qi) to make it such that I get the max of the above scr over :qi to bounds.upperQi and :ri to bounds.upperRi