日期:2014-05-16  浏览次数:20673 次

求一条SQL语句 着急 着急 着急 着急!!!!!

一个表:student

name yuwen shuxue yingyu banji 时间
小明 80 80 100 一班 2012.。。。。
小明 100 80 80 。。 。。
小张 80 100 80 。。 。。
小张 80 80 80 。。 。。


查询 一班的学生表中 语文最好的人姓名 分数 英语最好的人姓名 分数 数学最好的人姓名 分数

查询结果为


一班 小明 100 小明 100 小张 100

是mysql数据库
 求大神!

------解决方案--------------------
忘记加上班级了,这英语和拼音一起的混合,真是很别扭啊:
SQL code
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