title: MYSQL inline view query (top customer)
body: <p>I try to make a query, so that I can see who is the top customer in a month (every month since begin till now).</p>
  
  <p>Now I have the tables:</p>
  
  <p><strong>orders</strong> (<code>orderID</code>, <code>orderdate</code>, <code>customerID</code>, <code>Netamount</code>, <code>tax</code>, <code>totalamount</code>)</p>
  
  <p><strong>orderline</strong> (<code>orderlineID</code>, <code>orderID</code>, <code>prodID</code>, <code>quantity</code>, <code>orderdate</code>)</p>
  
  <p><strong>customer</strong> (<code>firstname</code> <code>lastname</code> <code>zip</code> <code>creditcardtype</code> etc.)</p>
  
  <p>I think the other tables aren't necessarily here.</p>
  
  <p>Of course there are customers who never bought a thing and customers who already bought plenty of times. </p>
  
  <p>Now I used this query: </p>
  
  <pre><code>    SELECT customerid, Sum(netamount) 
      FROM orders
      GROUP BY customerid limit 1000000;
  </code></pre>
  
  <p>Now I see all customers who already bought sth. with the total amount they paid.</p>
  
  <p>With the query </p>
  
  <pre><code>    SELECT YEAR ( Orderdate ) Year ,
      MONTHNAME ( Orderdate ) Month ,
      COUNT(*) TotOrd ,
      FROM orders
      GROUP BY YEAR ( Orderdate ),
      MONTH ( Orderdate );
  </code></pre>
  
  <p>I get a table where each row shows me the <code>Yea</code>r <code>Month</code> <code>Total order</code> (placed in that month). </p>
  
  <p>Still I want just to see <strong>the Top Customer of a month</strong>.</p>
  
  <p>I searched a lot in the internet still couldn't find that what I want (maybe I just googled wrong).  I know that I need at least one inline view still no idea how to realize it.</p>
  
  <p>Hope someone can help me out here.</p>