sql语句 关于查询

[复制链接]
查看11 | 回复3 | 2008-11-26 17:09:22 | 显示全部楼层 |阅读模式
例如一张表 student
有如下属性 id(pk) score1 score2 name
查询 2课学分总和最大的学生有关信息
我只能查到总和 也就是select max(score1+score2) from student
我想查下信息,怎么查。
答案正确的话,50分送上
score1 +score2 没想到这两个可以组合起来使用 我一直以为单一的才可以做条件
感谢,让我学到更多
这是我摸索出来的,有些繁琐
SELECT TOP 1 *
FROM student
GROUP BY id, score1, score2, nameORDER BY MAX(score1+ score2) DESC
其他人答案也谢谢,第1楼的 有错 2,3楼的明显就是错的 ,没有GROUP BY 谢谢

回复

使用道具 举报

千问 | 2008-11-26 17:09:22 | 显示全部楼层
select top1 * from (select id,(score1+score2)as zongfen from student order by score1+score2 desc)借鉴一楼的写法,呵呵...
回复

使用道具 举报

千问 | 2008-11-26 17:09:22 | 显示全部楼层
select * from student where score1 +score2 =(select max(score1 +score2 ) from student )...
回复

使用道具 举报

千问 | 2008-11-26 17:09:22 | 显示全部楼层
select top 2 * from (select (score1+score2)as zongfenfrom student order by zongfen) a...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行