日期:2014-05-16 浏览次数:20673 次
mysql> select -> banji, -> max(if(yuwen = max_yuwen, name, "")) as yuwen_name, -> max_yuwen as yuwen, -> max(if(shuxue = max_shuxue, name, "")) as shuxue_name, -> max_shuxue as shuxue, -> max(if(yingyu = max_yingyu, name, "")) as yingyu_name, -> max_yingyu as yingyu -> from -> student left join -> (select max(yuwen) as max_yuwen, max(shuxue) as max_shuxue, max(yingy u) as max_yingyu from student) as max_score -> on yuwen = max_yuwen or shuxue = max_shuxue or yingyu = max_yingyu -> group by banji; +-------+------------+-------+-------------+--------+-------------+--------+ | banji | yuwen_name | yuwen | shuxue_name | shuxue | yingyu_name | yingyu | +-------+------------+-------+-------------+--------+-------------+--------+ | 一班 | 小明 | 100 | 小张 | 100 | 小明 | 100 | +-------+------------+-------+-------------+--------+-------------+--------+ 1 row in set (0.00 sec)
------解决方案--------------------
select *
from
(select name,yuwen from student order by yuwen desc limit 1) a,
(select name,shuxue from student order by shuxue desc limit 1) b,
(select name,yingyu from student order by yingyu desc limit 1) c
------解决方案--------------------
select *
from
(select name,yuwen from student where banji='一班' order by yuwen desc limit 1) y,
(select name,shuxue from student where banji='一班' order by shuxue desc limit 1) s,
(select name,yingyu from student where banji='一班' order by yingyu desc limit 1) eng