Fix issue with SQLite 3.7.13 and aggregate in subquery