**Describe the bug**

When creating a funnel with $autocapture and css selector the postgresql query fails.

**To Reproduce**

Create the following funnel:

![Screenshot from 2020-06-24 23-08-13](https://user-images.githubusercontent.com/148820/85622527-a2f7df00-b66f-11ea-8463-c67ff0b54ab8.png)

**Expected behavior**

No crash

**Additional context**

The generated query is here:

```sql
SELECT
  "posthog_person"."id",
  "posthog_person"."created_at",
  "posthog_person"."team_id",
  "posthog_person"."properties",
  "posthog_person"."is_user_id",
  MIN("step_0"."step_ts") as "step_0"
FROM
  (
    SELECT
      "pdi"."person_id",
      MIN("posthog_event"."timestamp") AS "step_ts"
    FROM
      posthog_event
      JOIN posthog_persondistinctid pdi ON pdi.distinct_id = posthog_event.distinct_id
    WHERE
      (
        "posthog_event"."timestamp" >= '2020-06-17T00:00:00+00:00' :: timestamptz
        AND "posthog_event"."event" = '$autocapture'
        AND "posthog_event"."team_id" = 2
        AND EXISTS(
          SELECT
            W0."id"
          FROM
            posthog_event
            JOIN posthog_persondistinctid pdi ON (pdi.distinct_id = posthog_event.distinct_id) W0
          WHERE
            (
              W0."id" = "posthog_event"."id"
              AND W0."elements_hash" IN (
                SELECT
                  V0."hash"
                FROM
                  "posthog_elementgroup" V0
                WHERE
                  (
                    V0."team_id" = 2
                    AND (
                      SELECT
                        U0."order"
                      FROM
                        "posthog_element" U0
                      WHERE
                        (
                          U0."attr_class" @ > ARRAY ['foobar'] :: varchar(200) []
                          AND U0."group_id" = V0."id"
                        )
                      ORDER BY
                        U0."order" ASC
                      LIMIT
                        1
                    ) IS NOT NULL
                  )
              )
            )
        )
      )
    GROUP BY
      "pdi"."person_id"
  ) step_0
  JOIN posthog_person ON posthog_person.id = "step_0".person_id
WHERE
  "step_0".person_id IS NOT NULL
GROUP BY
  "posthog_person"."id",
  "posthog_person"."created_at",
  "posthog_person"."team_id",
  "posthog_person"."properties",
  "posthog_person"."is_user_id"
```

The syntax error is in this subquery:
```sql
          SELECT
            W0."id"
          FROM
            posthog_event
            JOIN posthog_persondistinctid pdi ON (pdi.distinct_id = posthog_event.distinct_id) W0
```

Have not yet dug into what causes the faulty query.
posthog/models/funnel.py
[sql.Identifier("posthog_person"), sql.Identifier("created_at")],
                         [sql.Identifier("posthog_person"), sql.Identifier("team_id")],
                         [sql.Identifier("posthog_person"), sql.Identifier("properties")],
                         [sql.Identifier("posthog_person"), sql.Identifier("is_user_id")]]
        QUERY_FOOTER = sql.SQL("""
            JOIN posthog_person ON posthog_person.id = {step0}.person_id
            WHERE {step0}.person_id IS NOT NULL
            GROUP BY {group_by}""")
        person_fields = sql.SQL(",").join([sql.SQL(".").join(col) for col in PERSON_FIELDS])
        steps = [sql.Identifier(step) for step, query in query_bodies.items()]
        select_steps = [sql.Composed([
            sql.SQL("MIN("),
            step,
            sql.SQL("."),
            sql.Identifier("step_ts"),
            sql.SQL(") as "),
            step
        ]) for step in steps]
        lateral_joins = []
        query = sql.SQL(QUERY_HEADER).format(
            fields=sql.SQL(',').join(select_steps),
            people=person_fields
        )
        i = 0
        for step, qb in query_bodies.items():
            if i > 0:
                
                q = qb.format(
                    prev_step_person_id=sql.Composed([steps[i-1], sql.SQL("."), sql.Identifier("person_id")]),
                    prev_step_ts=sql.Composed([steps[i-1], sql.SQL("."), sql.Identifier("step_ts")])