1:
create table student(
          studID varchar(5) not null,studName varchar(20)
         CONSTRAINT [PK_student] PRIMARY KEY  CLUSTERED 
(
studID
)  ON [PRIMARY] 
)ON [PRIMARY]
....

解决方案 »

  1.   

    5
    select 学号,avg(成绩) from 关联表 group by 学号
      

  2.   

    1. 创建3个表的SQL表名和字段名都使用英文,自行设计。(20分)*/create table STUDENT(SID int,Sname varchar(10))
    insert student values(20030405,'WAN')
    insert student values(20030406,'NAM')
    create table COURCE (CID int,CNAME varchar(4))
    insert COURCE values(1,'语文')
    insert COURCE values(2,'数学')
    create table SC(SID int,CID int,SCORE int)
    insert sc values(20030405,       1      ,   90)
    insert sc values(20030405 ,      2    ,     67)
    insert sc values(20030406   ,    2   ,      46)
    insert sc values(20030406   ,   1  ,       89)
    --2. 查询:学号为20030405的学生的语文、数学成绩,一行显示。(25分)select a.sid,max(case when b.CNAME='语文' then a.SCORE end) 语文,max(case when b.CNAME='数学' then a.SCORE end) 数学 from SC a join COURCE b on a.CID=b.CID where a.SID=20030405 group by a.sid--3. 查询: 学号为20030405的学生,最高分的科目(20分)select top 1 b.CNAME from SC a join COURCE b on a.CID=b.CID where a.SID=20030405 order by SCORE desc--4. 查询:语文最高分学生姓名(15分)select top 1 c.sNAME from SC a join COURCE b on a.CID=b.CID join student c on a.sid=c.sid  where b.CNAME='语文' order by SCORE desc--5. 查 询:每个学生的平均分(20分)select SID,avg(SCORE) SCORE from sc group by SID--------------------
    drop table SC,COURCE,STUDENT
      

  3.   

    1.学生表:字段有,学号,姓名 
    2.科目表:字段有,科目代号,科目名称 
    3.关联表 :字段有, 学号,科目代号,成绩,
    使用SQL语句完成如下功能:1. 创建3个表的SQL表名和字段名都使用英文,自行设计。(20分)--学生表
    create table tbstudent(sID varchar(10),sName varchar(20))
    --科目表
    create table tbsubject(subjectID varchar(10),subjectName varchar(50))
    --关联表
    create table tbjoin(sId varchar(10),subjectId varchar(10),result decimal(20,1))2. 查询:学号为20030405的学生的语文、数学成绩,一行显示。(25分)
    select a.sID,max(case b.subjectname when '语文' then b.result end) as 语文,max(case b.subjectname when '数学' then b.result end) as 数学
    from tbstudent a,(select a.subjectID,a.subjectName,b.result,b.sID from tbsubject a,tbjoin b where a.subjectid=b.subjectid) b
    where a.sid=b.sid and a.sid='20030405'
    group by a.sid
      

  4.   

    3. 查询: 学号为20030405的学生,最高分的科目(20分)select subjectname from tbsubject where subjectid=(select top 1 subjectid from(
    select subjectid,max(result) as result from tbjoin where sid='20030405' group by subjectid ) a)4. 查询:语文最高分学生姓名(15分)select sname from tbstudent where sid=(select top 1 sid from(select sid,max(result) as result from tbjoin where subjectid=(select top 1 subjectid from tbsubject where subjectname='语文') group by sid) a
    ))
      

  5.   

    5. 查 询:每个学生的平均分(20分)select a.sid,a.sname,avg(b.result)
    from tbstudent a,tbjoin b where a.sid=b.sid