text: Q:
  
  SQL two "group by" in the same query
  
  We have the table to track what product page a user visited. 
  product_tracking
  ____________________
  id  user_id  product
  1   1        A
  2   1        B
  3   2        A 
  4   1        A
  
  I know we can use group by user_id, and group_by product but I need both.  
  Expected result :
  result_table 
  ____________________________
  user_id      A     B    C 
    1          2     1    0
    2          1     0    0 
  
  any idea how to merge the 2 group by ? 
  
  A:
  
  You could do this:
  SELECT
      product_tracking.user_id,
      SUM(CASE WHEN product_tracking.product='A' THEN 1 ELSE 0 END) AS A,
      SUM(CASE WHEN product_tracking.product='B' THEN 1 ELSE 0 END) AS B,
      SUM(CASE WHEN product_tracking.product='C' THEN 1 ELSE 0 END) AS C
  FROM
      product_tracking
  GROUP BY
      product_tracking.user_id
  
  