欢迎投稿

今日深度:

学生表sid,sname,成绩表cid,cname,学生成绩表sid,cid,

学生表sid,sname,成绩表cid,cname,学生成绩表sid,cid,cscore,要求输出特地考生最高成绩的课程名称,snamecscore


--1、建表SQL:

--学生表:

-- Createtable

createtable STUDENT

(

  SID   NUMBERnotnull,

  SNAME NVARCHAR2(40)

)

tablespace CABLESCD

  pctfree10

  initrans1

  maxtrans255

  storage

  (

    initial64

    minextents1

    maxextentsunlimited

  );

--成绩表

-- Createtable

createtable SCORE

(

  CID   NUMBERnotnull,

  CNAME NVARCHAR2(40) notnull

)

tablespace CABLESCD

  pctfree10

  initrans1

  maxtrans255

  storage

  (

    initial64

    minextents1

    maxextentsunlimited

  );

--学生成绩表

-- Createtable

createtableSTUDENGSCORE

(

  SID    NUMBERnotnull,

  CID    NUMBERnotnull,

  CSCORE NUMBER(4,2)

)

tablespace CABLESCD

  pctfree10

  initrans1

  maxtrans255

  storage

  (

    initial64

    minextents1

    maxextentsunlimited

  );

--2、插入SQL语句:

insert into student

 (sid, sname)

values

  (001,'ZHAOHY');

 

insert into student

 (sid, sname)

values

 (002, 'ZHANGQL');

 insert into student

 (sid, sname)

values

 (003, 'ZHAOHB');

 

insert into score

 (cid, cname)

values

 (100, '数电');

 insert into score

 (cid, cname)

values

 (200, '模电');

 insert into score

 (cid, cname)

values

 (300, '英语');

   insert into score

 (cid, cname)

values

 (400, '政治');

select * from score

 

 (001, 100, '60');

 insert into studengscore

 (sid, cid, cscore)

values

 (002, 100, '70');

 insert into studengscore

 (sid, cid, cscore)

values

 (003, 100, '80');

 insert into studengscore

 (sid, cid, cscore)

values

 (003, 200, '90');

 insert into studengscore

 (sid, cid, cscore)

values

 (003, 300, '99');

 insert into studengscore

 (sid, cid, cscore)

values

 (003, 400, '98');

select * from studengscore

--3、查询SQL

 

select * fromstudengscore;

select * from student;

select * from score;

 

select cnamefrom score where cid =(select cid fromstudengscore wherecscore=(

selectmax(cscore) fromstudengscore where sid=3 ));



现在有学生表student(sid,sname),课程表crouse(cid,cname),成绩表grade(sid,cid,grade)现在要查询所

select s.sid,s.sName from s,c,g
where s.sid=g.gid and c.cid=g.cid
and grade>60
 

sql查询问题,有4个表,学生表(sid,sname,cid)课程表(课程ID,KCNAME)成绩表(sid,kcid,score),班级表

这是思路 不是答案
假设 班级是a表 班级对应的学生是b表

select a.*,b.chengji form a inner join b on a.xuehao=b.xuehao where 条件 order by id asc
 

www.htsjk.Com true http://www.htsjk.com/shujukunews/2837.html NewsArticle 学生表sid,sname,成绩表cid,cname,学生成绩表sid,cid,cscore,要求输出特地考生最高成绩的课程名称,snamecscore --1 、建表 SQL: --学生表: -- Createtable create table STUDENT ( SID NUMBER not null , SNAME NVARCH...
评论暂时关闭