On Fri, Apr 29, 2016 at 12:00 PM, Jann Roder <j.roder at wintoncapital.com> wrote:
> Hi, > It seems like a too obvious omission to not be intentional. But I wonder > why a query like > > SELECT SUM(A) > FROM TABLE > GROUP BY B > HAVING A <> 0 > > Is not rejected. MS SQL server gives you this error message in this case: > > Column ?A? is invalid in the HAVING clause because it is not contained in > either an aggregate function or the GROUP BY clause. > ?I agree that it just looks _wrong_. And PostgreSQL certainly complains about it.? > > It's not even clear to me what SQLite does with a query like that. > ?I executed the above both with the HAVING clause and without it. I also did an EXPLAIN on both. Judging by the EXPLAIN output and the actual output, what it seems to do is exclude rows which have SUM(A) equal to zero. I.e. the HAVING is acting on the SUM(A). > > Jann > -- The unfacts, did we have them, are too imprecisely few to warrant our certitude. Maranatha! <>< John McKown

