title: How can I return pivot table output in MySQL?
body: <p>If I have a MySQL table looking something like this:</p>
  
  <pre>
  company_name    action  pagecount
  -------------------------------
  Company A       PRINT   3
  Company A       PRINT   2
  Company A       PRINT   3
  Company B       EMAIL   
  Company B       PRINT   2
  Company B       PRINT   2
  Company B       PRINT   1
  Company A       PRINT   3
  </pre>
  
  <p>Is it possible to run a MySQL query to get output like this:</p>
  
  <pre>
  company_name    EMAIL   PRINT 1 pages   PRINT 2 pages   PRINT 3 pages
  -------------------------------------------------------------
  CompanyA        0       0               1               3
  CompanyB        1       1               2               0
  </pre>
  
  <p>The idea is that <code>pagecount</code> can vary so the output column amount should reflect that, one column for each <code>action</code>/<code>pagecount</code> pair and then number of hits per <code>company_name</code>. I'm not sure if this is called a pivot table but someone suggested that?</p>