title: What does SUM(a*b) do?
body: <p>I've never seen SUM(a*b) before.  I am hoping someone can tell me its intended behavior and if it is part of the SQL standard, or something MySQL just happens to implement.  An example:</p>
  
  <pre><code>localhost test&gt; CREATE TABLE numbers (id int not null primary key auto_increment, a int, b int);
  Query OK, 0 rows affected (0.03 sec)
  
  localhost test&gt; INSERT INTO numbers (a,b) VALUES (1, 2), (3,4),(1,1),(5,6);
  Query OK, 4 rows affected (0.00 sec)
  Records: 4  Duplicates: 0  Warnings: 0
  
  localhost test&gt; select * FROM numbers GROUP BY id;
  +----+------+------+
  | id | a    | b    |
  +----+------+------+
  |  1 |    1 |    2 |
  |  2 |    3 |    4 |
  |  3 |    1 |    1 |
  |  4 |    5 |    6 |
  +----+------+------+
  4 rows in set (0.00 sec)
  
  localhost test&gt; select SUM(a), SUM(b) FROM numbers GROUP BY id;
  +--------+--------+
  | SUM(a) | SUM(b) |
  +--------+--------+
  |      1 |      2 |
  |      3 |      4 |
  |      1 |      1 |
  |      5 |      6 |
  +--------+--------+
  4 rows in set (0.00 sec)
  
  localhost test&gt; select SUM(a*b), SUM(a), SUM(b) FROM numbers GROUP BY id;
  +----------+--------+--------+
  | SUM(a*b) | SUM(a) | SUM(b) |
  +----------+--------+--------+
  |        2 |      1 |      2 |
  |       12 |      3 |      4 |
  |        1 |      1 |      1 |
  |       30 |      5 |      6 |
  +----------+--------+--------+
  4 rows in set (0.00 sec)
  
  localhost test&gt; alter table numbers add col2 int not null;
  Query OK, 4 rows affected (0.03 sec)
  Records: 4  Duplicates: 0  Warnings: 0
  
  localhost test&gt; update numbers set col2 = id %2;
  Query OK, 2 rows affected (0.00 sec)
  Rows matched: 4  Changed: 2  Warnings: 0
  
  localhost test&gt; select col2, SUM(a*b), SUM(a), SUM(b) FROM numbers GROUP BY col2;
  +------+----------+--------+--------+
  | col2 | SUM(a*b) | SUM(a) | SUM(b) |
  +------+----------+--------+--------+
  |    0 |       42 |      8 |     10 |
  |    1 |        3 |      2 |      3 |
  +------+----------+--------+--------+
  2 rows in set (0.01 sec)
  </code></pre>
  
  <p>I would have expected 80 and 30 in the last row, or an error produced if it used MySQL's non-standard behavior of picking one row (I have SQL_MODE=ONLY_FULL_GROUP_BY enabled).</p>