51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2050|回复: 3
打印 上一主题 下一主题

[求助] oracle 查询求助

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2015-5-1 14:41:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
有三个表学生表table1:  studentid  studentname   科目表subject1:   subjectid   subjectname  分数表score1 :  studentid  subjectid  score   
问题是 语文数学课总分前10名的学生号,姓名,总分??该怎么写出来的,菜鸟求助大神们
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    开心
    2016-1-7 15:07
  • 签到天数: 98 天

    连续签到: 2 天

    [LV.6]测试旅长

    2#
    发表于 2015-5-1 17:35:11 | 只看该作者
    select student.studentname, aa.* from student,(select studentid as 'id', sum(score) as 'SUM' from score where score.subjectid in (1,2) group by studentid ) as aa where aa.id = student.studentid order by SUM desc limit 10;
    上面语句中的1,2指的是语文数学的id。我自己建表的时候写的语文数学ID是1,2.这里改成你自己的id。
    我运行了一下是可以得到你想要的结果的。几年前学的知识都忘没了。。。惭愧啊。。
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-6-16 15:53
  • 签到天数: 4 天

    连续签到: 1 天

    [LV.2]测试排长

    3#
    发表于 2015-5-2 22:57:56 | 只看该作者
    select * from (select a.*,rownum rm from
    (select min(st.studentid) "学号",st.studentname "姓名",sum(sc.score) "总分"
    from student st,subject1 su, score1 sc
    where st.studentid=sc.studentid and su.subjectid=sc.subjectid  
    and su.subjectname in('china','math') group by st.studentname order by sum(sc.score) desc
    ) a) where rm<=10;
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-6-16 15:53
  • 签到天数: 4 天

    连续签到: 1 天

    [LV.2]测试排长

    4#
    发表于 2015-5-2 23:00:31 | 只看该作者
    select * from (select a.*,rownum rm from
    (select min(st.studentid) "学号",st.studentname "姓名",sum(sc.score) "总分"
    from student st,subject1 su, score1 sc
    where st.studentid=sc.studentid and su.subjectid=sc.subjectid  
    and su.subjectname in('china','math') group by st.studentname order by sum(sc.score) desc
    ) a) where rm<=10;
    我做的有点麻烦,里面有两个子查询,还用到了伪劣。
    技术不精,望指教。
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-22 07:10 , Processed in 0.067806 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表