distinct
使用sum的行。
+-------+-----+------+------+------+-------+
| users | ref | add | sub | mul | marks |
+-------+-----+------+------+------+-------+
| u1 | 20 | 4521 | | | 20 |
| u1 | 20 | 4522 | | | 80 |
| u1 | 20 | 4523 | | | 60 |
| u1 | 20 | | 8565 | | 70 |
| u1 | 20 | | 8566 | | 30 |
| u1 | 20 | | | 5135 | 10 |
| u2 | 15 | 4521 | | | 20 |
| u2 | 15 | 4522 | | | 20 |
| u2 | 15 | | 6253 | | 30 |
| u3 | 20 | 5236 | | | 40 |
| u3 | 20 | | 4523 | | 50 |
| u3 | 20 | | 4524 | | 5 |
| u3 | 20 | | 4525 | | 30 |
| u3 | 20 | | | 5135 | 20 |
+-------+-----+------+------+------+-------+
group by
却没有得到这个结果。
+-------+-----+-----+-----+-----+-------+
| users | ref | add | sub | mul | total |
+-------+-----+-----+-----+-----+-------+
| u1 | 20 | 3 | 2 | 1 | 270 |
| u2 | 15 | 2 | 1 | n/a | 70 |
| u3 | 20 | 1 | 3 | 1 | 145 |
+-------+-----+-----+-----+-----+-------+