SQLite Forum

Can this simple query be optimized?
This query would return only a single value of "x" from the group where that value of "x" corresponds to "some row" on which "one of the minima or maxima" were found (the last such row "visited" actually).

The original request was:

For each grouping of 10 x's (x // 10) find:  
 - The maximum Y and (one of) the X on which that maximum occurs; and,  
 - The minimum Y and (one of) the X on which that minimum occurs.  

The only case in which the two X values are the same are the case in which the Y value of all rows comprising the group are the same.

A query such as:

select x/10, min(y), max(y) from foo group by x/10;

would indeed return the "group number" and the min/max for that group using a single table scan, however, that is not the data that is being sought.