title: SQL Select: How to multiply a column with the count of an ID
body: <p>I have the following (here simplified) database and want to get the month with the highest revenue. </p>
  
  <p><strong>invoices</strong><br>
  - id<br>
  - order_id<br>
  - issued (timestamp)</p>
  
  <p><strong>orders</strong><br>
  - id</p>
  
  <p><strong>orderItems</strong><br>
  - id<br>
  - order_id<br>
  - article_id</p>
  
  <p><strong>articles</strong><br>
  - id<br>
  - price</p>
  
  <p>So far I got the following statement:</p>
  
  <pre><code>Select articles.price * orderItems.order_id as revenue, Extract(month 
  from invoices.issued) 
  FROM orderItems
  INNER JOIN articles ON orderItems.article_id = articles.id
  Inner JOIN orders ON orderItems.order_id = orders.id
  Inner JOIN invoices ON orders.id = invoices.order_id
  GROUP BY year(issued), month(issued)
  Order by revenue DESC Limit 1
  </code></pre>
  
  <p>The calculated revenue is wrong as the price is multiplied with the order_id but should be actually multiplied with the count of the respective order_id. I tried to implement count(orderItems.order_id) but it's not working. Any ideas? Thanks!</p>