title: MySQL SUM function and CASE statement
body: <pre>
  SELECT 
      CASE schuleArtID 
          WHEN 1 THEN SUM(schuleSummeSchueler) / 8
          WHEN 2 THEN SUM(schuleSummeSchueler) / 6 * 0.8
          WHEN 3 THEN SUM(schuleSummeSchueler) / 6 * 0.8
          WHEN 4 THEN SUM(schuleSummeSchueler) / 5 * 0.8
          WHEN 5 THEN SUM(schuleSummeSchueler) / 3 * 0.5
          WHEN 6 THEN SUM(schuleSummeSchueler) / 3 * 0.8
      END AS potenzial
  FROM 
      sys_theorie_schule
  WHERE
      filialID = '311'
  GROUP BY
      schuleArtID
  </pre>
  
  <p>This works, but now I need a sum because there are multiple rows.</p>
  
  <pre>
  SELECT 
      SUM(
          CASE schuleArtID 
              WHEN 1 THEN SUM(schuleSummeSchueler) / 8
              WHEN 2 THEN SUM(schuleSummeSchueler) / 6 * 0.8
              WHEN 3 THEN SUM(schuleSummeSchueler) / 6 * 0.8
              WHEN 4 THEN SUM(schuleSummeSchueler) / 5 * 0.8
              WHEN 5 THEN SUM(schuleSummeSchueler) / 3 * 0.5
              WHEN 6 THEN SUM(schuleSummeSchueler) / 3 * 0.8
          END
      ) AS potenzial
  FROM 
      sys_theorie_schule
  WHERE
      filialID = '311'
  GROUP BY
      schuleArtID
  </pre>
  
  <p>Here, I only get the result <code>[Err] 1111 - Invalid use of group function</code>.</p>
  
  <p>Here is the structure of the table (Sorry for the German column names):</p>
  
  <pre>
  CREATE TABLE `sys_theorie_schule` (
    `schuleID` int(11) NOT NULL AUTO_INCREMENT,
    `filialID` int(11) NOT NULL,
    `schuleName` varchar(255) NOT NULL,
    `schuleStrasse` varchar(255) NOT NULL,
    `schulePlz` varchar(8) NOT NULL,
    `schuleOrt` varchar(255) NOT NULL,
    `schuleArtID` int(11) NOT NULL,
    `schuleSummeSchueler` int(11) NOT NULL,
    `schuleEntfernung` int(11) NOT NULL,
    `online` tinyint(1) NOT NULL DEFAULT '1',
    `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`schuleID`)
  ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8
  </pre>
  
  <p>MySQL-Version: 5.0.51a-24+lenny5</p>
  
  <p>Could somebody help, please?
  Many thanks!</p>