View Ticket
Not logged in
Ticket UUID: f7f8c97e975978d45cc2b1ea722af90e0607adc6
Title: Valid query fails to compile due to WHERE clause optimization
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2016-04-25 02:20:09
Version Found In: 3.12.2
User Comments:
drh added on 2016-04-25 01:43:33: (text/x-fossil-wiki)
The following query works and gives the correct answer for SQLite version 3.8.10
but fails to compile with a "misuse of aggregate" error for 3.8.11.

CREATE TABLE t1(a int, b int);
INSERT INTO t1 VALUES(1,2),(1,18),(2,19);
  SELECT a AS x, sum(b) AS y FROM t1 GROUP BY a
  SELECT 98, 99
) AS w WHERE y>=20;

The problem seems to have been introduced by check-in [6df18e949d36] on [2015-06-02].
The problem was reported on the sqlite-users mailing list by
Jean-Luc Hainaut.