我创建了四个表
第一个表:学生表
Create table student(
sid  number(20)  primary key ,
sname nvarchar2 (20) not null,
gender  nvarchar2(1) constraint  g_ck check (gender  in ('m','w')),
age number(3) not null,
birthday nvarchar2(30) not null,
address nvarchar2(50) not null,
political nvarchar2(50) not null,
college nvarchar2(50) not null,
branches nvarchar2(20) not null,
class nvarchar2(20) not null
);第二个表:课程表
create table course(
cid number(20) primary key,
cname nvarchar2(20) not null,
credit number(4) not null,
hour nvarchar2(20) not null,
total number(3) not null,
description nvarchar2(200) not null
);
insert into  course  第三个表:教师表
Create table teacher(
tid number(20) primary key,
tname nvarchar2(20) not null,
gender  nvarchar2(1)  constraint  t_ck check (gender  in ('m','w')),
age number(3) not null,
college nvarchar2(50) not null,
title nvarchar2(20) not null,
branches nvarchar2(20) not null,
professional nvarchar2(100) not null
);
第四个表:选课信息表
4.
course_info
create table course_info (
sid  number (sequence) references student(sid),
tid number(sequence) references teacher(tid),
cid number(sequence) references course(cid),
counter number(5) not null,
check_date date(20) not null,
open_date date(20) not null,
teach_date date(20) not null
);
我想实现以下功能,请问应该怎么写查询语句呢
1.学生根据所在院系的名称(college),查看本学期所开设的课程的课程编号(cid),课程名称(cname),开课人数(total),
任课教师名称(tname),以及授课时间(teach_date).
2.根据学号(sid)查询该生的姓名(sname),学号(sid),课号(cid),课程名称(cname),以及讲该课程的教师的姓名(tname)
3.教师根据教师编号(tid)可以查看自己所教课程的名称(tname),开课时间(open_date),选课人数(counter)信息。
4.查询学生选择课程人数最多的前三门课程的课程编号(cid),课程名称(cname),授课教师(tname),从而对其进行教学评估。

解决方案 »

  1.   

    1,sql如下:   select c.cid, c.cname, c.total, t.tname, ci.teach_date from  student s,course c, teacher t, course_info ci 
       where s.name='张三' and s.college=t.college 
             and ci.tid=t.tid and ci.cid=c.cid
      

  2.   

    1,假如学生是张三,sql如下:   select c.cid, c.cname, c.total, t.tname, ci.teach_date from  student s,course c, teacher t, course_info ci 
       where s.name='张三' and s.college=t.college 
             and ci.open_date>sysdate --本学期所开的课程
             and ci.tid=t.tid and ci.cid=c.cid
      

  3.   

    2,sql 如下:select s.sname, s.sid, c.cid, c.cname, t.tname from student s,course c, teacher t, course_info ci 
         where s.sid='20090102' and s.sid=ci.sid and ci.cid=c.cid and ci.tid=t.tid
      

  4.   

        由于我是自学oracle,能力很有限,恳请大家能帮忙看以下,第三个第四个应该怎么作呢?
      

  5.   

    3.教师根据教师编号(tid)可以查看自己所教课程的名称(tname),开课时间(open_date),选课人数(counter)信息。 
    select c.cname,ci.open_date, ci.counter from course c, teacher t, course_info ci 
          where t.tid='20090101' and t.tid=ci.tid and c.cid=ci.cid and 
    4,查询学生选择课程人数最多的前三门课程的课程编号(cid),课程名称(cname),授课教师(tname),从而对其进行教学评估。
       select b.cid,
              (select c.cname from course c where c.cid=b.cid and rownum<2) as cname,
              (select t.tname from teacher t where t.tid=b.tid and rownum<2) as tname            
       from
       (   
         select a.*,a.rownum rn from 
         ( select cid,tid,count(*) total_ci from course_info ci group by cid,tid ) a order by a.total_ci desc
       )b where rn<4
      

  6.   

      
      1  select course_info.cid,course.cname,teacher.tname from (
      2  select course_info.cid,course.cname,teacher.tname
      3  from course,teacher,course_info
      4  where course.cid=course_info.cid
      5  and teacher.tid=course.cid
      6  order by
      7  (select course_info.counter
      8  from course_info)desc)
      9* where rownum<4  我是这样写的第四个不知道怎么总是报错阿..
      

  7.   

    你的第4个表看起来设计是有问题的,你刚才本身发过这个贴了吧?
    表里面有sid,tid,cid 3个字段了,还加上一个count,这个count没有什么意义。这个count只是0,1两个值?所以他没有意义。
    应该有一个教师和课程之间的关系,来确定哪一门课哪个(或哪几个)老师教,或者哪一个老师教哪几门课。
    这样才能真正符合你的需求。
      

  8.   


    报什么ora错误啊?贴出来看下!