《大数据库练习及问题详解.doc》由会员分享,可在线阅读,更多相关《大数据库练习及问题详解.doc(10页珍藏版)》请在课桌文档上搜索。
1、word一. 创建一个学生档案表(表名为xsda),其表结构如下:列名类型长度允许空备注XhChar10学号XmChar8csnyDatetime出生年月GzDecimal6工资ZyChar10专业Create Table xsda(xhChar(10) not null unique,xmChar(8),csnyDatetime,gz Decimal(6,1),zy Char(10)1. 在xsda表中插入一个学生记录:2000jsj008,平insert into xsda(xh,xm) values(2000jsj008,平)2. 把xsda表中80-01-01前出生的人的工资增加20%
2、Update xsda set gz=gz*1.2 where csny 80-01-013. 查询xsda表中不同专业的人数Select zy ,count(xh) from xsda group by zy4. 假设另外还有一个学生成绩表xscj(xh,kch,kccj), xh,kch,kccj分别指学号、课程号、成绩,要求查询为平的同学的各门课程的成绩。Select kch,kccj from xsda,xscj where xsda.xh=xscj.xh and xm= 平5. xsda、xscj表同上,查询选修了kch为Yy2的学生的xh和XmSelect xh,xm from x
3、sda,xscj where xsda.xh=xscj.xh and kch=Yy2二、使用SQL语句创建一个班级表CLASS,属性如下:CLASSNO,DEPARTNO,CLASSNAME;类型均为字符型;长度分别为8、2、20且均不允许为空。CREATE _table_ CLASS(CLASSNO _char_(8) NOT NULL,DEPARTNO CHAR (2) NOT NULL,CLASSNAMECHAR (_20_) NOT NULL三、有一个学生课程数据库,数据库中包括三个表:学生表:Student由学号(Sno)、(Sname)、性别(Ssex)、年龄(Sage)、所在系(
4、Sdept)五个属性组成,记为:Student(Sno,Sname,Ssex,Sage,Sdept),Sno 为关键字。课程表:Course由课程号(o)、课程名(ame)、先修课号(Cpno)、学分(Ccredit)四个属性组成,记为: Course(o,ame,Cpno,Ccredit) o为关键字。 成绩表:SG由学号(Sno)、课程号(o)、成绩(Grade)三个属性组成,记为: SG(Sno,o,Grade) (SNO, O) 为关键字。用SQL语言实现如下功能:1建立学生表Student,其中学号属性不能为空,并且其值是唯一的。2查考试成绩有不与格的学生的学号。3将学号为05001
5、学生的年龄改为22岁。4计算1号课程的学生平均成绩。5. 查计算机系姓的男同学的(Sname)、性别(Ssex)、年龄(Sage)。6将一个新学生记录(学号:05020;:丁莉;性别:女;年龄:17岁;所在系:计算机;)插入Student表中。1create table student (Sno char(5) primary key,Sname char(20),Ssex char(2),Sage int,Sdept char(15)2select distinct sno from sgwhere grade 1970-01-015、 查询工资高于2000元的员工的信息。Select *
6、from employee where Salary20006、 查询系统集成部的所有员工的信息。Select employee.* from employee,departments where employee. Depart=departments. Depdid and Depname= 系统集成部7、 统计软件开发部的人均工资select avg(salary) from employee, departments where employee. Depart=departments. Depdid and Depname= 软件开发部8、 查询所有员工中工资最高和最低的人。Sele
7、ct * from employee where saraly=(select max(saraly) from employee)goSelect * from employee where saraly=(select min(saraly) from employee)9、 统计软件开发部的人数。select count(*) from employee, departments where employee. Depart=departments. Depdid and Depname= 软件开发部10、 将所有员工的工资上调10%。11、 将工资收入低于2500元的员工每人加薪200元。Update employee set gz=gz+200 where saray5014、删除所有1970年以前出生的员工的信息。 Delete from employee where birthdate1970-01-0110 / 10