title: MYSQL - Ordered query with a limit and grouped by two fields
body: <p>I originally posted this, but everything was wrong(unclear, no example, etc) so I took the time to put this together and properly ask this.</p>
  <p>This was a question for me in a technical interview and I failed it hard.
  I need some insight on how to do it.</p>
  <p>Sample table is as such...</p>
  <p>Table(Orders)</p>
  <p>Fields =
  Order ID | Company | Sale | Month</p>
  <pre><code>Orders
  Order ID | Company | Sale | Month
         1 | A       |    7 | Jan
         2 | A       |    3 | Feb
         3 | B       |    2 | Feb
         4 | B       |    8 | Jan
         5 | C       |    4 | Feb 
         6 | C       |    6 | Jan
         7 | B       |    3 | Mar
         8 | C       |    6 | Mar
         9 | A       |    7 | Mar
  </code></pre>
  <p>Where the output would be like:</p>
  <pre><code> Company | Sale | Month
   B       |    8 | Jan
   A       |    7 | Jan
   C       |    4 | Feb
   A       |    3 | Feb 
   A       |    7 | Mar
   C       |    6 | Mar
  </code></pre>
  <p>How do I get the top two companies by Sales per month? (3 months for our purposes)</p>
  <p>So I tried this</p>
  <pre><code>SELECT
  Company,
  SUM(Sale) AS Total,
  Month
  FROM Orders
  Group by Month, Company
  ORDER BY Total DESC;
  </code></pre>
  <p>Note there are at least 3 companies, and there could be multiple rows for a company in a single month.</p>
  <p>If I limit 6, it wouldn't necessarily include all months if that's the case.(If some months are better, I could get 3 entries for one of the months for example, all of Jan is better than Feb)</p>
  <p>I got the hint of using a subquery, but even then I was a bit lost.</p>
  <p>I tried doing a subquery that returns two companies but do note that the same top two list of companies won't be the same for all the months</p>
  <p>So my expected output is 6 rows with varying companies (not always the same 2) and in different order, with different sales, comprised of 3 different top two lists (one for each month) all in one query.</p>
  <p>If this is simple, I really bombed my interview but any help would be appreciated.
  Hope this is understandable</p>