title: Simplifying SQL query
body: <p>I'm using the Bixi public dataset found at <a href="https://www.bixi.com/en/open-data" rel="nofollow noreferrer">https://www.bixi.com/en/open-data</a> and have been asked to find &quot;the average number of trips a day for each year-month combination in the dataset&quot;. Here's an example of the table from which I'm querying:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>start_date</th>
  <th>start_station_code</th>
  <th>end_date</th>
  <th>end_station_code</th>
  <th>duration_sec</th>
  <th>is_member</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>85843</td>
  <td>2016-04-15 00:00:00</td>
  <td>6315</td>
  <td>2016-04-15 00:05:00</td>
  <td>6315</td>
  <td>349</td>
  <td>1</td>
  </tr>
  <tr>
  <td>85844</td>
  <td>2016-04-15 17:16:00</td>
  <td>6315</td>
  <td>2016-04-15 17:37:00</td>
  <td>6315</td>
  <td>1293</td>
  <td>0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The query that I used to successfully answer the question was as follows, but how can I simplify it?:</p>
  <pre><code>SELECT
      daily_trips_2016.avg_daily_trips AS avg_daily_trips_2016,
      daily_trips_2017.avg_daily_trips AS avg_daily_trips_2017,
      daily_trips_2016.month
  FROM
      (
      SELECT -- This sub-query determines the average number of daily trips per month for the year 2016
          ROUND(COUNT(*) / (COUNT(DISTINCT DAY(start_date))), 0) AS avg_daily_trips,
          MONTH(start_date) AS month
      FROM trips
      WHERE YEAR(start_date) = 2016
      GROUP BY month) AS daily_trips_2016
  LEFT JOIN
      (
      SELECT -- This sub-query determines the average number of daily trips per month for the year 2017
          ROUND(COUNT(*) / (COUNT(DISTINCT DAY(start_date))), 0) AS avg_daily_trips,
          MONTH(start_date) AS month
      FROM trips
      WHERE YEAR(start_date) = 2017
      GROUP BY month) AS daily_trips_2017
  ON daily_trips_2016.month = daily_trips_2017.month; -- Since both sub-queries share the &quot;month&quot; column, the JOIN happens on this column
  -- and we can see the daily averages side by side for each year
  </code></pre>