**Goal**: Output only (category, sum of incidents) for each day of the week (unique) across 2018. 

i.e. Show the *top* category and its total sum of incidents for each day of the week. There should therefore only be 7 rows with this dataset (but `LIMIT 7` doesn't really answer the core problem I'm trying to understand)

Using BigQuery Standard SQL:

```
SELECT
    dayofweek,
    category,
    SUM(incident_count) as incidents
FROM
    (SELECT dayofweek, category, count(*) as incident_count
    FROM `bigquery-public-data.san_francisco.sfpd_incidents`
    WHERE
        EXTRACT(year from timestamp) = 2018
    GROUP BY
        category, dayofweek
) incidents_2018
GROUP BY
    category,
    dayofweek
ORDER BY incidents DESC

```

---

I've tried writing a `HAVING` clause with a sub-query to filter the aggregated results - resembling `HAVING incidents > (SELECT count(*) FROM sfpd_incidents WHERE ...)` - but I'm stuck in understanding what that sub-query should look like.

```
|dayofweek|         category          |incidents|
|---------|---------------------------|--------:|
|Monday   |LARCENY/THEFT              |      228|
|Wednesday|LARCENY/THEFT              |      210|
|Tuesday  |LARCENY/THEFT              |      194|
|Thursday |LARCENY/THEFT              |      119|
|Friday   |LARCENY/THEFT              |      118|
|Saturday |LARCENY/THEFT              |      115|
|Sunday   |LARCENY/THEFT              |      108|
# this should be the cut-off point - only show the
# top category & its count for each dayofweek
# incident counts that aren't the "top" for each
# dayofweek should be excluded from the result set.
|Monday   |NON-CRIMINAL               |      105|
|Tuesday  |OTHER OFFENSES             |       91|
|Wednesday|OTHER OFFENSES             |       85|
|Tuesday  |NON-CRIMINAL               |       78|
|Monday   |OTHER OFFENSES             |       72|
|Monday   |ASSAULT                    |       68|
|Wednesday|NON-CRIMINAL               |       62|
|Tuesday  |ASSAULT                    |       62|
|Wednesday|ASSAULT                    |       51|
|Sunday   |ASSAULT                    |       50|
|Thursday |ASSAULT                    |       47|

```