title: Sum(Case when) resulting in multiple rows of the selection
body: <p>I have a huge table of customer orders and I want to run one query to list orders by month for the past 13 months by 'user_id'.  What I have now (below) works but instead of only listing one row per user_id it lists one row for each order the user_id has.  Ex: one user has 42 total orders over his life with us so it lists his user_id in 42 rows and each row only has one payment.  Typically I would just throw this in a pivot table in excel but I'm over the million row limit so I need for it to be right and have had zero success.  I would like for the read out to look like this:</p>
  
  <p>user_id | jul_12 | aug_12 |</p>
  
  <p>123456  | 150.00 | 150.00 |</p>
  
  <p>Not this:</p>
  
  <p>user_id | jul_12 | aug_12 |</p>
  
  <p>123456  |   0.00 | 150.00 |</p>
  
  <p>123456  | 150.00 |   0.00 |</p>
  
  <p>etc. 40 more rows</p>
  
  <pre><code>SELECT ui.user_id, 
  SUM(CASE WHEN date_part('year', o.time_stamp) = 2012 AND date_part('month', o.time_stamp) = 07 THEN o.amount ELSE 0 END) jul_12,
  SUM(CASE WHEN date_part('year', o.time_stamp) = 2012 AND date_part('month', o.time_stamp) = 08 THEN o.amount ELSE 0 END) aug_12,
  FROM orders o JOIN users_info ui ON ui.user_id = o.user_id
  WHERE user_id = '123456'
  GROUP BY ui.user_id, o.time_stamp;
  </code></pre>