I am trying to find how many times the primary_type of 'crime' happened each year.
The Dataset is on KAGGLE.
https://www.kaggle.com/datasets/currie32/crimes-in-chicago
and I downloaded it and uploaded it into BigQuery.
SELECT
DISTINCT
primary_type
FROM bigquery-public-data.chicago_crime.crime
https://i.stack.imgur.com/ThBZK.jpg
I ran this query and I know that their are 36 different primary_type's of crimes that are linked with specific codes the primary key for the codes is "iucr". But, I just want to count how many times each of the separate 36 primary_type show up each year. Can someone help me?
SELECT
DISTINCT
primary_type
FROM bigquery-public-data.chicago_crime.crime
ORDER BY
year
I tried this but it gave me an error saying, "ORDER BY clause expression references column year which is not visible after SELECT DISTINCT at [6:3]".
Do I need to do a subquery? I'm still learning those.