数据库复习题

2026/1/15 21:52:37

order by s_sex

compute count(s_no) by s_sex

--(2)所有男生的姓名、出生日期、年龄

select s_name,birthday,year(getdate())-year(birthday) as age from student1

where s_sex = '男'

--(4)所有学生的姓名、出生日期、年龄、选修的课程和成绩。 select s_name,birthday,year(getdate())-year(birthday) as age,c_no,score

from student1 s inner join sco c on s.s_no = c.s_no

--(5)某个指定姓名学生的成绩。 select s_name,score

from student1 s join sco c on s.s_no = c.s_no where s_name = 'ae'

--(6)不及格学生的姓名。 select s_name,score

from student1 s join sco c on s.s_no = c.s_no where score < 60

--(7)按性别进行分组查询,查询男女生的平均成绩。 select s_sex,avg(score) as average from student1 s join sco c on s.s_no = c.s_no

--where c.c_no = 1 --查询指定课程的平均成绩 group by s_sex /* 2. 使用如下个表,写出操作语句。 部门:部门号,部门名,负责人,电话

职工:部门号,职工号,姓名,性别,出生日期 工资:职工号,基本工资,津贴,奖金,扣除 (1) 查询职工的实发工资。 (2) 查询年月日出生的职工信息。 (3) 查询每个部门年龄最长者的信息,要求显示部门名称和最长者的出生日期。 (4) 查询所有目前年龄在岁以上(不含岁)的职工姓名、性别和年龄。 (5) 查询有名以上(含名)职工的部门名称和职工人数,并按职工人数降序排

9

序。 */

create database test use test go

create table 部门 (

部门号char(2) not null, 部门名char(40) not null, 负责人char(10) not null, 电话char(11) )

create table 职工 (

部门号char(2) not null, 职工号char(6) not null, 姓名char(10) not null, 性别char(2) not null, 出生年月datetime )

create table 工资 (

职工号char(6) not null, 基本工资float not null, 津贴float not null, 奖金float, 扣除float )

--(1)查询职工的实发工资。

select 职工号,基本工资+津贴+奖金-扣除as 实发工资 from 工资

--(2)查询年月日出生的职工信息。 select * from 职工

where 出生年月='1962-10-27'

--(3)查询每个部门年龄最长者的信息,要求显示部门名称和最长者的出生日期。

select 部门名,min(出生年月) as 最长者出生日期 from 职工zg join 部门bm on zg.部门号=bm.部门号 group by 部门名

--(4)查询所有目前年龄在岁以上(不含岁)的职工姓名、性别和年龄。

10

select 姓名,性别,year(getdate())-year(出生年月) as 年龄 from 职工

where year(getdate())-year(出生年月)>35

--(5)查询有名以上(含名)职工的部门名称和职工人数,并按职工人数降序排序

select 部门号,count(部门号) from 职工

group by 部门号

having count(部门号)>1

order by count(部门号) desc

select 部门名,count(zg.部门号) as 人数 from 职工zg join 部门bm on zg.部门号=bm.部门号 group by 部门名

having count(zg.部门号)>1

order by count(zg.部门号) desc

11


数据库复习题.doc 将本文的Word文档下载到电脑
搜索更多关于: 数据库复习题 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219