select sum(case when a.user_id=1 then b.kills end) as 'wukong',
sum(case when a.user_id=2 then b.kills end) as 'bajie',
sum(case when a.user_id=3 then b.kills end) as 'shaseng'
from user a join user_kills b on a.user_id = b.user_id group by b.user_id;
结果如下:
+--------+-------+---------+
| wukong | bajie | shaseng |
+--------+-------+---------+
| 50722 | NULL | NULL |
| NULL | 15310 | NULL |
| NULL | NULL | 2100 |
+--------+-------+---------+
3 rows in set (0.00 sec)
把group by 那句删掉