This appears to have nothing to do with window functions.  The use of window
functions in the example above merely disables the query flattener.  The
problem can also be seen in the following query:

<blockquote><verbatim>
CREATE TABLE t1 (a);
CREATE TABLE t2 (b);
CREATE TABLE t3 (c);
CREATE TABLE t4 (d);
INSERT INTO t1 (a) VALUES (104);
INSERT INTO t2 (b) VALUES (104);
INSERT INTO t3 (c) VALUES (104);
INSERT INTO t4 (d) VALUES (104);

-- Disable the query-flattener
.testctrl optimizations 0x01

SELECT *
FROM t1 CROSS JOIN t2 ON (t1.a = t2.b) WHERE t2.b IN (
  SELECT t3.c
  FROM t3
  WHERE t3.c IN (
    SELECT d FROM (SELECT d FROM t4) AS innermost WHERE innermost.d=104
  )
);


The query above fails in all versions of SQLite from 3.8.11 and later.  The
check-in that causes the failure is [020b8b106fc8f840f6b506e1c9c3b] on
2015-05-29