title: MySQL return month by month count for each distinct ID
body: <p>I wrote the below query, which works, but it is incredibly inefficient and slow.  What can I do to make it more efficient?  I understand that it's basically "looping" over each ID in the system, there's about 500 of them, and running 13 select statements for each one - I just don't know a better way to get this information.  </p>
  
  <p>My date field is a <code>DATE</code> field stored as <code>YYYY-MM-DD</code>.</p>
  
  <pre><code>SELECT 
  id as name,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-01-01' AND '2017-01-31') and id = name)  as January,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-02-01' AND '2017-02-31') and id = name)  as February,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-03-01' AND '2017-03-31') and id = name)  as March,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-04-01' AND '2017-04-31') and id = name)  as April,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-05-01' AND '2017-05-31') and id = name)  as May,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-06-01' AND '2017-06-31') and id = name)  as June,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-07-01' AND '2017-07-31') and id = name)  as July,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-08-01' AND '2017-08-31') and id = name)  as August,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-09-01' AND '2017-09-31') and id = name)  as September,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-10-01' AND '2017-10-31') and id = name)  as October,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-11-01' AND '2017-11-31') and id = name)  as November,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-12-01' AND '2017-12-31') and id = name)  as December,
   (SELECT sum(captured_profit) from me where (date BETWEEN '2017-11-01' AND '2017-12-31') and id = name)  as Total,
  from me
  where id is not null
  group by id;
  </code></pre>