整理的sql sever一些数据库查询面试题
当然,我整理的只是一些常见的面试题,具体数据库就不给了,相信大家能看懂!!!
--2列出EMPLOYEES表中各部门的部门号,最高工资,最低工资
select Max(salary) as '最高工资',Min(salary) as '最低工资' ,department_id as '部门号' from Employees group by department_id --3列出EMPLOYEES表中各部门EMPLOYEE_JOB为'职员'的员工的最低工资,最高工资
select Max(salary) as '最高工资',Min(salary) as '最低工资' ,department_id as '部门号' from Employees
where employee_job='职员' group by department_id --4对于EMPLOYEES中最低工资小于5000的部门,列出EMPLOYEE_JOB为'职员'的员工的部门号,最低工资,最高工资 select a.department_id as '部门号',Max(a.salary) as '最高工资',Min(a.salary) as '最低工资' from Employees
as a where >(select Min(salary) from Employees as b where a.Department_Id=b.Department_Id ) and a.Employee_Job='职员'
group by a.department_id select a.department_id as '部门号',Max(a.salary) as '最高工资',Min(a.salary) as '最低工资' from Employees
as a group by a.department_id --根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资 select a.employee_name as '姓名',a.department_id as '部门号',a.salary as '工资' from Employees as
a order by a.Department_Id desc,a.salary asc --6列出'刘备'所在部门中每个员工的姓名与部门号 select a.employee_name as '姓名',a.department_id as '部门号' from Employees as a
where a.Department_Id=(select Department_Id from Employees as b where b.Employee_Name='刘备') --7列出每个员工的姓名,工作,部门号,部门名 select employee_name ,Employee_job ,employees.department_id,department_name from employees inner join
departments on employees.Department_Id=Departments.Department_ID --8列出EMPLOYEES中工作为’职员'的员工的姓名,工作,部门号,部门名 select employee_name ,Employee_job ,employees.department_id,department_name from employees inner join
departments on employees.Department_Id=Departments.Department_ID where Employees.Employee_Job='职员' --8对于DEPARTMENTS表中,列出所有部门名,部门号,同时列出各部门工作为'职员'的员工名与工作 select Departments.Department_Name as '部门名称',Departments.Department_ID as '部门号',Employees.Employee_Name as '员工名',Employees.Employee_Job as '工作' from Departments
left join Employees on Departments.Department_ID=Employees.Department_Id where Employees.Employee_Job='职员' --9对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序 select a.department_id as '部门号',a.employee_name as '姓名',a.salary as '工资' from Employees
as a where a.Salary>(select avg(salary) from Employees as b where a.Department_Id=b.Department_Id)
order by a.Department_Id SELECT
Employees.department_id,
Employee_name,
Salary
FROM
Employees,
(SELECT
AVG(salary) as 'avg',
department_id
FROM
Employees
GROUP BY
department_id) as t
WHERE
salary > t.avg
and Employees.Department_Id = t.Department_Id select a.department_id as '部门号',a.employee_name as '姓名',a.salary as '工资' from Employees
as a select avg(salary) from Employees where Department_Id=
select avg(salary) from Employees where Department_Id=
select avg(salary) from Employees where Department_Id= select * from Employees --10对于EMPLOYEES,列出各个部门中工资高于本部门平均水平的员工数和部门号,按部门号排序 select count(*) as '员工数',a.department_id as '部门号',avg(salary) as '平均工资' from Employees as a
where a.Salary>(select avg(salary) from Employees as b where a.Department_Id=b.Department_Id)
group by a.Department_Id having count(a.Department_Id) > order by a.Department_Id select salary from Employees where Department_Id= --11对于EMPLOYEES中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序 select count(*) as 员工数,a.DEPARTMENT_ID as 部门号,avg(SALARY) as 平均工资 from EMPLOYEES as a where (select count(c.EMPLOYEE_ID) from EMPLOYEES as c where c.DEPARTMENT_ID = a.DEPARTMENT_ID and c.SALARY>(select avg(SALARY) from EMPLOYEES as b where c.DEPARTMENT_ID = b.DEPARTMENT_ID))> group by a.DEPARTMENT_ID order by a.DEPARTMENT_ID select count(*) as 员工数,a.DEPARTMENT_ID as 部门号,avg(SALARY) as 平均工资 from EMPLOYEES as a group by a.DEPARTMENT_ID order by a.DEPARTMENT_ID select * from Employees --12对于EMPLOYEES中低于自己工资至少5人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数 select a.DEPARTMENT_ID,a.EMPLOYEE_NAME,a.SALARY,(select count(*) from EMPLOYEES as b where b.SALARY < a.SALARY) as 人数 from EMPLOYEES as a where (select count(*) from EMPLOYEES as b where b.SALARY<a.SALARY)>
整理的sql sever一些数据库查询面试题的更多相关文章
- Sql Sever 2012数据库更名失败 error:5030
打开SQL Server 2012数据库时,对HzWind_2MW数据库名修改为HzWind_2MW_GEM,结果出现如图1所示: 图1 数据库更名时出现error:5030 数据库不能重名名5030 ...
- sql sever误删数据库
在sql sever 2008 r2中,我想把一个数据库添加到DATA中,结果发现被占用,我就打算解除占用后再进行复制,本来应该先是让数据库脱离,再复制,结果,我自作聪明地右键数据库,选择了删除,结果 ...
- sql sever跨数据库复制数据的方法【转】
1,用Opendatasource系统函数 详细的用法已经注释在sql代码中了.这个是在sqlserver到sqlserver之间的倒数据.2005,2008,2012应该都是适用的. --从远程服务 ...
- SQL Server 跨数据库查询
语句 SELECT * FROM 数据库A.dbo.表A a, 数据库B.dbo.表B b WHERE a.field=b.field "DBO"可以省略 如 SELECT * F ...
- sql server多数据库查询 远程数据库查询
--创建链接服务器 exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','服务器地址' exec sp_addlinkedsrvlogin 'srv_lnk ...
- sql sever跨数据库复制数据的方法
1,用Opendatasource系统函数 详细的用法已经注释在sql代码中了.这个是在sqlserver到sqlserver之间的倒数据.2005,2008,2012应该都是适用的. --从远程服务 ...
- Pl/sql Dev登录数据库查询报ORA-03114
pl/sql dev能正常登录数据库,但是登录后执行查询报 ORA-03114异常. 1.建议安装PL/SQL Dev的32位版,64位版不太好用,且需要64位对应的OCI.DLL. 64位简直不要太 ...
- sql sever 跨库查询
reconfigure reconfigure select * from openrowset( 'SQLOLEDB', '192.168.1.180'; 'sa'; '123.com',joybl ...
- 我们在删除SQL Sever某个数据库表中数据的时候,希望ID重新从1开始,而不是紧跟着最后一个ID开始需要的命令
一.如果数据重要,请先备份数据 二.删除表中数据 SQL: Delete From ('表名') 如:Delete From abcd 三.执行新语句 SQL: dbcc checkident('表 ...
随机推荐
- spring-security 登陆认证之初次探究
首先,希望还对 spring-security框架完全不懂的新手 下载下Git源码. 引入到项目中.这个短文就是边看源码边聊的.也会启动下项目验证自己的推想. 一.登陆认证的登陆配置项 <for ...
- Sql Server添加用户
1.sa用户登陆之后,在安全性中新建登录名 2.添加登录名,下面的默认数据库选择该用户可访问的默认数据库 3.服务器角色中选择public 4.用户映射中选择该用户可访问的数据库,数据库角色一般选择p ...
- smarty练习:数据的增删改
根据数据库中的三张表格:timu,xuanxiang,kemu来进行数据的增删改查,并且使用smarty模版将前端与后台分离开来 三张表格: 主页面后台 main.php: <?php //引入 ...
- 现有有N个学生的数据记录,每个记录包括学号、姓名、三科成绩。 编写一个函数input,用来输入一个学生的数据记录。 编写一个函数print,打印一个学生的数据记录。 在主函数调用这两个函数,读取N条记录输入,再按要求输出。 N<100
#include <iostream> using namespace std; struct student {char num[100]; char name[100]; int ...
- ARM 之FIQ(快速中断) IRQ(中断)
IRQ,FIQ定义: 这就是个普通中断,当我们程序定义了该中断,并且在程序运行的时候产生了IRQ中断,则此时的芯片是这样运行的------中断处理器吧利用IRQ请求线来高速ARM,ARM就知道有个I ...
- uml(1)--概述
面象对象的课程已经学到UML建模部分, 为了应付老师布置了的作业,须重新学习UML 故趁此机会将自己所学,所看做个记录,不为点赞, 只为加深记忆,加深理解…不是都说写一遍等于读十遍嘛…… 对于UML ...
- 自制单片机之十五……可串行驱动LCD12864的应用
在网上搜了一下,ST7920控制器的LCD产品可以提供8位,4位并行和串行接口可选,并行的控制接口的LCD较多,前面的贴子也介绍过,我们在这儿不说了,这儿我们讲的是串口控制LCD12864. 买了块S ...
- rpm -qs查看包信息
rpm -qs mysql-connector-c-devel Query options (with -q or --query): -c, --configfiles ...
- bzoj1178
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1178 看ppt http://wenku.baidu.com/link?url=dJv6LNm ...
- strcat函数的坑点
我们先看下面这样一段代码: #include <iostream> #include <stdlib.h> using namespace std; int main() { ...