Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mportocarrero/8385491 to your computer and use it in GitHub Desktop.
Save mportocarrero/8385491 to your computer and use it in GitHub Desktop.
Query 18 - How many bikes were stolen in average per month in Tower Hamlets from May to October 2013? This query shows the average of bikes stolen per month in Tower Hamlets.
Query in MySql:
mysql> select borough, date, count(*) as count from bike where borough = 'Tower Hamlets' group by date;
+---------------+------------+-------+
| borough | date | count |
+---------------+------------+-------+
| Tower Hamlets | 2013-05-01 | 17 |
| Tower Hamlets | 2013-06-01 | 33 |
| Tower Hamlets | 2013-07-01 | 24 |
| Tower Hamlets | 2013-08-01 | 23 |
| Tower Hamlets | 2013-09-01 | 28 |
| Tower Hamlets | 2013-10-01 | 33 |
+---------------+------------+-------+
6 rows in set (0.00 sec)
mysql> select avg(count) from (select borough, date, count(*) as count from bike where borough = 'Tower Hamlets' group by date) as c;
+------------+
| avg(count) |
+------------+
| 26.3333 |
+------------+
1 row in set (0.00 sec)
Note: this quote is only going to be quoted in the blog text and not turned into a graph, therefore the results are not output in Python.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment