在mysql数据库中有一张人物表t_character,字段名及数据如下:
现在有一个需求,需要查询出攻击力与防御力之和排名前三的人物,并按其速度从大到小排序。
难点在于同一条记录中的不同字段求和排序,这里用到一个mysql中不常用的函数sumcol:
select * from t_character a right join ( select id,(attack+defence)SUMCOL from t_character order by SUMCOL desc limit 3) b on a.id = b.id order by speed desc