title: How to select max of count in PostgreSQL
body: <p>I have table in PostgreSQL with the following schema:</p>
  
  <pre><code>Category    |   Type 
  ------------+---------
  A           |   0 
  C           |   11 
  B           |   5 
  D           |   1 
  D           |   0 
  F           |   2   
  E           |   11 
  E           |   9 
  .           |   . 
  .           |   .
  </code></pre>
  
  <p>How can I select category wise maximum occurrence of type? The following give me all:</p>
  
  <pre><code>SELECT 
      category, 
      type, 
      COUNT(*)
  FROM 
      table
  GROUP BY 
      category, 
      type
  ORDER BY 
      category, 
      count 
      DESC
  </code></pre>
  
  <p>My expected result is something like this:</p>
  
  <blockquote>
    <p>Cat     |Type |Count<br>
    --------+-------+------</p>
    
    <p>A     |0      |5 </p>
    
    <p>B     |5      |30</p>
    
    <p>C     |2      |20</p>
    
    <p>D     |3      |10</p>
  </blockquote>
  
  <p>That is the type with max occurrence in each category with count of that type. </p>