选课系统有三个表
create table student(stu_no varchar(4) primary key,stu_name varchar(10) not null,gender varchar(5),stu_age number(2) check(stu_age>=16 and stu_age<40),stu_dto varchar(20));
create table course(course_no varchar(4) primary key,course_name varchar(20) not null,cou_teacher varchar(10));
create table elective(stu_no varchar(4), course_no varchar(4),point number(3) check(point is null or point between 0 and 100),primary key(stu_no,course_no));
然后插入的数据,查询某位授课老师所授课程中分数最高的那位学生的名字及成绩
select stu_name,point
from student,course,elective,(select course_no,max(point) from elective group by as temp(course_no,max))
where student.stu_no=elective.stu_no and course.course_no=elective.course_no
and point=max and course.course_no=temp.course_no;
运行结果是ORA-00933:sql命令未正常结束,报错的星号停在as上,大家帮我看下

解决方案 »

  1.   

    贴错了,group by后面丢了course_no
      

  2.   

    select stu_name,point
    from student,course,elective,(select course_no,max(point) from elective group by course_no,max)
    where student.stu_no=elective.stu_no and course.course_no=elective.course_no
    and point=max and course.course_no=temp.course_no;
      

  3.   

    select stu_name,point
    from student,course,elective,(select course_no,max(point) max_point from elective group by course_no))
    where student.stu_no=elective.stu_no and course.course_no=elective.course_no
    and point=max_point  and course.course_no=temp.course_no;
      

  4.   

    with temp as
    (select course_no,max(point) from elective group by course_no)
    select stu_name,point
    from student,course,elective,temp
    where student.stu_no=elective.stu_no and course.course_no=elective.course_no
    and point=max and course.course_no=temp.course_no;
      

  5.   

    with temp as
    (select course_no,max(point) max_p from elective group by course_no)
    select stu_name,point
    from student,course,elective,temp
    where student.stu_no=elective.stu_no and course.course_no=elective.course_no
    and point=max_p and course.course_no=temp.course_no;
      

  6.   

    多谢ls,可以运行,我很奇怪为什么我按照下面的这条语法来写都会报错
    SELECT column_name
    FROM table_name  AS table_alias
    难道是因为在oracle下运行的原因