On Thu, 11 Apr 2013 17:14:43 +0200
Clemens Ladisch <[email protected]> wrote:

> >> It should come (or be derived) from the current row in the outer
> >> query.
> >
> > Sorry, but inner queries are performed first.
> 
> Sorry, but *correlated* inner queries are performed once for each
> record in the outer query.

*Logically* performed, you mean.  It's helpful to think of correlated
subqueries as being performed once per row.  It's also helpful to
remember there is no "before" or "after" while a query is executing.
The DBMS is free to execute your query in whatever fashion it chooses.  

Your query is incorrectly construed, however, 

        select (select 42 limit 1 offset (select t.x)) from t;

assumes IIUC an order to t that isn't there, and a count that can't, in
general, be known.  

The only way to compute a median is to sort and count the input first.
That can be done by joining the table to itself to get an ordinal, and
by testing that product against itself in an EXISTS clause.  

The other way is to write a UDF, which isn't too hard if you assume all
value can be represented as double-precision floating point.  

--jkl
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to