SQL查询语句

1、(1)查询person表中所有不重复的职称

use pay115

select distinct professor

from person

 

2查询person中男员工的信息

use pay115

select *

from person

where sex = '男'

 

(3)查询person表中00102部门女员工的信息

use pay115

select *

from person

where sex = '女' and deptno = '00102'

 

 

(4)查询000001员工的基本工资增长1.5倍后的实际收入

use pay115

select base*1.5+bonus-deduct as real_fact

from pay

where no = '000001'

 

(5)查询00102部门的员工的基本信息和工资情况,按实发工资降序排列

use pay115

select *

from person left outer join pay on (person.No = pay.no)

where person.DeptNo = '00102'

order by fact desc

 

(6)查询各部门2005年实发工资总数

use pay115

select deptno as 部门,sum(fact) as 总额

from pay,person

where pay.no=person.no and year=2005

group by deptno

 

(7)查询20051月平均奖金不少于400的部门,按平均奖金升序排列

use pay115

select dept.deptno,deptname ,avg(bonus) as 平均奖金

from dept,person,pay

where year = 2005 and month = 1 and dept.deptno = person.DeptNo and pay.No = person.No

group by dept.deptno,deptname

having avg(bonus)>=400

order by avg(bonus) asc

 

(8)查询市场部所有员工姓名和20051月工资明细

use pay115

select name,base,bonus,deduct,fact

from person,pay,dept

where person.no = pay.no and year = 2005 and month = 1 and dept.deptname = '市场部' and dept.DeptNo = person.DeptNo

 

2、利用SQL语句嵌套查询

(1)查询20051月比000001员工实发工资高的所有员工的基本信息

use pay115

select *

from person

where no in

(

select no from pay

where year = 2005 and month = 1 and 

fact>(select fact from pay

where year = 2005 and month = 1 and no = '000001')

)

 

 

(2)查询20051月比00102部门的所有员工实发工资都高的员工信息

use pay115

select *

from person

where no in

(

select no from pay

where year = 2005 and month = 1 and 

fact>(select max(fact) 

from pay,person

where year = 2005 and month = 1 and deptno = '00102' and person.no = pay.no)

)

 

(3)查询20051月比所有员工平均实发工资都高的员工基本信息和工资明细

use pay115

select *

from person,pay

where person.no = pay.no and pay.no in

(

select no from pay

where year = 2005 and month = 1 and 

fact>(select avg(fact) 

from pay

where year = 2005 and month = 1)

)

 

3、利用SQL语句创建视图

(1)在基表person基础上创建员工视图view_person,其中包括工号,姓名、性别、职称、部门代码字段

create view dbo.view_person(No,Name,Sex,professor,deptno)

as

select no,name,sex,professor,deptno

from dbo.person

 

(2)

create view dbo.view_pay(year,month,no,name,sex,professor,deptname,base,bonus,deduct,fact)

as

select year,month,person.no,name,sex,professor,deptname,base,bonus,deduct,fact

from dbo.person,dbo.pay,dbo.dept

where dept.DeptNo = person.DeptNo and person.no = pay.no

 

 

 

三、SQL查询语言实验:

补充题:必做题4题,另外书上例题自选2题:

1、查询平均成绩大于60分的课程的课程号和平均成绩。

use school 

select cno,avg(grade) from sc group by cno having avg(grade)>60

 

 

2、查询没有选修“数据库”课程的学生的学号和姓名。

use school

select sno,sname

from student

where sno not in

(select sno

from sc,course

where cname = '数据库' and course.cno = sc.cno)

 

 

3、查询选修人数超过2人的课程的课程号(如果加课程名称,可以实现吗?)和学生人数。查询结果按人数降序排列,若人数相同,按课程号升序排列。

use school

select cno,count(sno)

from sc

group by cno

having count(sno)>2           

order by count(sno) desc,cno asc

 

加课程名:

use school

select sc.cno,count(sno),cname

from sc,course

where course.cno = sc.cno

group by sc.cno,cname

having count(sno)>1          

order by count(sno) desc,cno asc

 

4、创建视图view_sc,查询有学生选修的课程的课程号,课程名,学分和选修人数。

create view view_sc(cno,cname,ccredit, 选课人数)

as 

select course.cno,cname,ccredit,count(sno)

from course,sc

where course.cno = sc.cno

group by course.cno,cname,ccredit

having count(sno)>0

 

3.22 查询计算机科学系全体学生的名单

select sname

from student

where sdept = 'cs'

 

 

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值