当然,我整理的只是一些常见的面试题,具体数据库就不给了,相信大家能看懂!!!

--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一些数据库查询面试题的更多相关文章

  1. Sql Sever 2012数据库更名失败 error:5030

    打开SQL Server 2012数据库时,对HzWind_2MW数据库名修改为HzWind_2MW_GEM,结果出现如图1所示: 图1 数据库更名时出现error:5030 数据库不能重名名5030 ...

  2. sql sever误删数据库

    在sql sever 2008 r2中,我想把一个数据库添加到DATA中,结果发现被占用,我就打算解除占用后再进行复制,本来应该先是让数据库脱离,再复制,结果,我自作聪明地右键数据库,选择了删除,结果 ...

  3. sql sever跨数据库复制数据的方法【转】

    1,用Opendatasource系统函数 详细的用法已经注释在sql代码中了.这个是在sqlserver到sqlserver之间的倒数据.2005,2008,2012应该都是适用的. --从远程服务 ...

  4. SQL Server 跨数据库查询

    语句 SELECT * FROM 数据库A.dbo.表A a, 数据库B.dbo.表B b WHERE a.field=b.field "DBO"可以省略 如 SELECT * F ...

  5. sql server多数据库查询 远程数据库查询

    --创建链接服务器 exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','服务器地址' exec sp_addlinkedsrvlogin 'srv_lnk ...

  6. sql sever跨数据库复制数据的方法

    1,用Opendatasource系统函数 详细的用法已经注释在sql代码中了.这个是在sqlserver到sqlserver之间的倒数据.2005,2008,2012应该都是适用的. --从远程服务 ...

  7. Pl/sql Dev登录数据库查询报ORA-03114

    pl/sql dev能正常登录数据库,但是登录后执行查询报 ORA-03114异常. 1.建议安装PL/SQL Dev的32位版,64位版不太好用,且需要64位对应的OCI.DLL. 64位简直不要太 ...

  8. sql sever 跨库查询

    reconfigure reconfigure select * from openrowset( 'SQLOLEDB', '192.168.1.180'; 'sa'; '123.com',joybl ...

  9. 我们在删除SQL Sever某个数据库表中数据的时候,希望ID重新从1开始,而不是紧跟着最后一个ID开始需要的命令

    一.如果数据重要,请先备份数据 二.删除表中数据 SQL: Delete From ('表名')  如:Delete From abcd 三.执行新语句 SQL: dbcc checkident('表 ...

随机推荐

  1. Oracle 执行计划(Explain Plan)

    如果要分析某条SQL的性能问题,通常我们要先看SQL的执行计划,看看SQL的每一步执行是否存在问题. 如果一条SQL平时执行的好好的,却有一天突然性能很差,如果排除了系统资源和阻塞的原因,那么基本可以 ...

  2. objectivc-c---block

    基本格式: returnType (^blockName[num])(paramList|void) = ^returnType(paramList|void){block Body}; 标红部分可根 ...

  3. xml bug

    在Eclipse 创建动态WEB 工程,在src 下 创建 config.xml: 1 <?xml version="1.0" encoding="UTF-8&qu ...

  4. 【vc】5_文本编程

    1.插入符(Caret): (1) 文本插入符 函数的原型声明:(CWnd类) void CreateSolidCaret ( int Nwidth, int nHeight ); ·nwidth:指 ...

  5. R语言学习网站

    一个不错的个人R语言博客网站 http://blog.fens.me/r-overview/

  6. WPF中TextBox限制输入不起作用的问题

    最近再用textbox做限制输入时遇到一个莫名其妙的问题: 首先看代码: <TextBox  Name="txtip1" Height="40" Widt ...

  7. CSS中cursor的pointer 与 hand-备

    cursor:hand 与 cursor:pointer 的效果是一样,都像手形光标(在浏览器上时   鼠标会显示成 小手 ).但用FireFox浏览时才注意到使用cursor:hand在FireFo ...

  8. LeetCode_Best Time to Buy and Sell Stock III

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  9. C++中new和delete的背后( call edx 调用虚表内的第二个函数(析构函数))

    关于 C++中new背后的行为, 以前已经写过一篇了 理解C++中new背后的行为, 但是里面也只是泛泛而谈,没有真凭实据, 下面我们从汇编的角度看C++编译器究竟在背后干了什么?   我们的代码很简 ...

  10. Delphi7下实现HTTP的Post操作 转

    Delphi7下实现HTTP的Post操作 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Gra ...