整理的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('表 ...
随机推荐
- Arcgis - Personal Geodatabase 和 File Geodatabase的区别.
一.平台支持: 1.Personal Geodatabase:仅可在Windows 上运行: 2.File Geodatabase:跨平台支持,可在Windows 及UNIX.linux上运行. 评 ...
- JS将图片文件转为64位字符串再post到接口上传图片
HTML: <div class="ai-item upload-id-img"> <p>上传身份证照片</p> <div class=& ...
- 如何发布Web项目到互联网
比如我们有个项目想要发布到互联网上,我们首先需要购买域名以及主机,主机的话,推荐云主机(本人推荐西部数码或者阿里云),性能好: 我们先在云主机上搭建环境,比如Mysql,Jdk,Tomcat: 然后我 ...
- AVL树相关操作
#include <iostream> using namespace std; //AVL树的节点 template<typename T> class TreeNode { ...
- 最近公共祖先:LCA及其用倍增实现 +POJ1986
Q:为什么我在有些地方看到的是最小公共祖先? A:最小公共祖先是LCA(Least Common Ancestor)的英文直译,最小公共祖先与最近公共祖先只是叫法不同. Q:什么是最近公共祖先(LCA ...
- PHP echo, print, printf, sprintf函数的区别和使用
1. echo函数: 输出函数,是命令,不能返回值.echo后面可以跟很多个参数,之间用分号隔开,如: echo $myvar1; echo 1,2,$myvar,"<b>bol ...
- angular ng-bind-html 对src路径失效 解决方案
json内容 ;<img src="/newsfile/1506271512489.jpg" width="600" height="450&q ...
- 类和对象:一些相关的BIF - 零基础入门学习Python040
类和对象:一些相关的BIF 让编程改变世界 Change the world by program 一些类和对象相关的 BIF 今天我们来谈谈跟类和对象相关的一些BIF(内置函数): issubcla ...
- strcpy and memcpy
1. Inconsist length. char a3[2]; char *a = "Itis " strcpy(a3, a); It is wrong. a3 will b ...
- Linux_Shell符号及各种解释对照表
Shell符号及各种解释对照表: Shell符号 使用方法及说明 # 注释符号(Hashmark[Comments]) 1.在shell文件的行首,作为shebang标记,#!/bin/bash; 2 ...