Skip to main content

To obtain part sums of a column based on specific conditions, use If() or CASE, eg...

SELECT
  sum(IF(condition1, col, 0)) AS cond1,
  sum(IF(condition2, col, 0)) AS cond2
  -- ...etc...
FROM
  tbl;