Simplified test case:

<blockquote><pre>
CREATE TABLE t1 (
  id1 INTEGER PRIMARY KEY AUTOINCREMENT,
  value1 INTEGER
);
INSERT INTO t1 VALUES(4469,2),(4476,1);
CREATE TABLE t2 (
  id2 INTEGER PRIMARY KEY AUTOINCREMENT,
  value2 INTEGER
);
INSERT INTO t2 VALUES(0,1),(2,2);
SELECT
 (SELECT sum(value2==xyz) FROM t2)
FROM
 (SELECT curr.value1 as xyz
    FROM t1 AS curr LEFT JOIN t1 AS other
   GROUP BY curr.id1);