整理的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('表 ...
随机推荐
- 第11章 集合、比较和转换(C#入门经典第6版)
1.集合 数据有一定的限制,最不能忍受的是一旦创建,数组的大小就固定,不能再添加.而集合则包含了数组所具有的功能,且可以任意添加/删减元素项,还有一些其他 功能. 集合的功能主要通过接口来实现,接口包 ...
- C#中的委托是什么?
概述 委托类似C++中的函数指针,但是又有所不同.在C++中,函数指针不是类型安全的,它指向的是内存中的某一个位置,我们无法判断这个指针实际指向什么,对于参数和返回类型就更难以知晓.而.NET的委托则 ...
- 3步学会用gulp
1.安装gulp 安装gulp到全局:npm install -g gulp 安装gulp到某个项目:npm install --save gulp 注意:请先安装nodejs(自带npm) 2.创建 ...
- 面试题:获取大量数据中某一条的index
提问: 群里分享了一个面试题:页面里有很多条数据,怎么知道这条数据的index,并且不使用循环? 分析: 如果在数组里,直接用indexOf,但对于对象会比较麻烦. 在页面上,不使用循环的话,可以用定 ...
- jquery正则表达式显示文本框输入范围 只能输入数字、小数、汉字、英文字母的方法
正则表达式限制文本框只能输入数字 许多时候我们在制作表单时需要限制文本框输入内容的类型,下面我们用正则表达式限制文本框只能输入数字.小数点.英文字母.汉字等各类代码.1.文本框只能输入数字代码(小数点 ...
- C++ 的多重继承
不能够从对象访问基类的公开方法,真悲剧!只能在类里面提供公共函数! void Mentor::GetInfo(){ cout<<endl<<name<<endl&l ...
- C语言初学 使用while语句统计输入字符个数
#include<stdio.h> main() { int n=0; printf("输入任意个数的字符:\n"); while(getchar()!='\n')n+ ...
- ARM的两种启动方式 (NAND FLASH. NOR FLASH)
为什么会有两种启动方式? 这就是有两种FLASH 的不同特点决定的. NAND FLASH 容量大,存储的单位比特数据的成本要低很多,但是要按照特定的时序对NAND FLASH 进行读写,因此CP ...
- 安装Hadoop集群的最快的软件
Quick Hadoop是一款安装Hadoop集群的桌面软件,只需要点两下鼠标,一分钟之内安装Hadoop到集群上,超快! 还在每台主机的Shell里一行一行地敲安装Hadoop的命令?别苦逼了! 用 ...
- Feedly订阅Blog部落格RSS网摘 - Blog透视镜
网络信息爆炸的时代,如何更有效率地阅读文章,订阅RSS网摘,可以快速地浏览文章标题,当对某些文章有兴趣时,才点下连结连到原网站,阅读更详细的文章,Feedly Reader阅读器除了提供在线版订阅RS ...