title: Understanding how WHERE works with GROUP BY and Aggregation
body: <p>My query - </p>
  
  <pre><code>select cu.CustomerID,cu.FirstName,cu.LastName, COUNT(si.InvoiceID)as inv --1
  from Customer as cu inner join SalesInvoice as si --2
  on cu.CustomerID = si.CustomerID -- 3
  -- put the WHERE clause here ! --4   
  group by cu.CustomerID,cu.FirstName,cu.LastName -- 5
  where cu.FirstName = 'mark' -- 6
  </code></pre>
  
  <p>Output with correct code - </p>
  
  <p><img src="https://i.stack.imgur.com/gg99e.jpg" alt="enter image description here"></p>
  
  <p>Error i get - Incorrect syntax near the keyword 'where'.</p>
  
  <p>Can you tell me why I get this error ? <strong>I want to know why WHERE comes before GROUP BY and not after.</strong></p>