PLSQL 的简单命令之三
-- 查找两个表中ID相等的
select a.id, a.name,b.math from stu a,scores b where a.id = b.id -- 右外连接
select b.id, a.name,b.math from stu a,scores b where a.id(+) = b.id
select b.id, a.name,b.math from stu a right outer join scores b on a.id = b.id -- 左外连接
select a.id, a.name,b.math from stu a,scores b where a.id = b.id(+)
select a.id, a.name,b.math from stu a left outer join scores b on a.id = b.id --1. 显示所有员工的姓名,部门号和部门名称。
select a.last_name ,b.department_id,b.department_name
from employees a ,departments b --2. 查询90号部门员工的job_id和90号部门的location_id
select a.job_id ,b.location_id from employees a ,departments b
where b.department_id=90 /*3. 选择所有有奖金的员工的
last_name , department_name , location_id , city
*/
select a.last_name,b.department_name,b.location_id,c.city
from employees a,departments b,locations c /*4. 选择city在Toronto工作的员工的
last_name , job_id , department_id , department_name
*/
select a.last_name,a.job_id,b.department_id,b.department_name
from employees a,departments b ,locations
where locations.city = 'Toronto' /*5. 选择指定员工的姓名,员工号,以及他的管理者的姓名和员工号,结果类似于下面的格式
employees Emp# manager Mgr#
kochhar 101 king 100
*/
select a.last_name
as employees ,a.employee_id
as emp#,b.last_name
as manager,b.employee_id
as mgr#
from employees a,employees b
where a.manager_id = b.employee_id(+) --查询公司员工工资的最大值,最小值,平均值,总和
select max(salary) from employees
select min(salary) from employees
select avg(salary) from employees
select sum(salary) from employees --查询各job_id的员工工资的最大值,最小值,平均值,总和
select job_id, max(salary),min(salary),avg(salary),sum(salary)
from employees
group by job_id --选择具有各个job_id的员工人数
select job_id,count(job_id)
from employees
group by job_id --查询员工最高工资和最低工资的差距(DIFFERENCE)
select max(salary)-min(salary) as difference from employees /*查询各个管理者手下员工的最低工资,
其中最低工资不能低于6000,
没有管理者的员工不计算在内
*/
select manager_id,min(salary)
from employees
where manager_id is not null
having min(salary)>=6000
group by manager_id --查询所有部门的名字,location_id,员工数量和工资平均值
select a.department_name,a.location_id,count(b.employee_id),avg(b.salary)
from departments a full outer join employees b
on a.department_id = b.department_id
group by a.department_name,a.location_id /*查询公司在1995-1998年之间,每年雇用的人数,结果类似下面的格式
total 1995 1996 1997 1998
20 3 4 6 7
*/
/*
select count(*), to_char(hire_date,'yyyy') from employees
where to_char(hire_date,'yyyy') between '1995' and '1998'
group by to_char(hire_date,'yyyy')
*/ /*decode(字段或字段的运算,值1,值2,值3)
这个函数运行的结果是,当字段或字段的运算的值等于值1时,该函数返回值2,否则返回值3
当然值1,值2,值3也可以是表达式,这个函数使得某些sql语句简单了许多
*/ select count(*),count(decode(to_char(hire_date,'yyyy'),'',1,null)) "1995",
count(decode(to_char(hire_date,'yyyy'),'',1,null)) "1996" ,
count(decode(to_char(hire_date,'yyyy'),'',1,null)) "1997",
count(decode(to_char(hire_date,'yyyy'),'',1,null)) "1998"
from employees
where to_char(hire_date,'yyyy') between '' and ''
PLSQL 的简单命令之三的更多相关文章
- PLSQL 的简单命令之五
--1. 查询和Zlotkey相同部门的员工姓名和雇用日期 select a.last_name,a.hire_date ,b.department_name from employees a,dep ...
- PLSQL 的简单命令之四
-- 子查询 -- in 等于表中的任意一个 select * from Stu where id in (select id from scores) -- 和子查询返回结果中的某一个值比较成立即可 ...
- PLSQL 的简单命令之二
--1. 查询工资大于12000的员工姓名和工资 --2. 查询员工号为176的员工的姓名和部门号 ' --3. 选择工资不在5000到12000的员工的姓名和工资 --4. 选择雇用时间在1998- ...
- Apache 的搭建及vim的简单命令
一. vim 简单命令 pwd 当前路径 ls 当前路径所有目录 cd 目录地址 跳转到指定目录 /xxx 查找xxx x 删除当前字符 n 执行上一次查找 二.为什么使用apa ...
- ORACLE的安装与网页版创建表空间的简单操作以及PLsql的简单操作
1.oracle的安装: 安装简单易学,在这里不做解释.下载看装包后耐心等待,注意安装目录不要有中文字符,尽量按照指定目录进行安装.安装完成后会占用有大约5g的内存. 如果要卸载oracle,需要用其 ...
- 从零单排Linux – 1 – 简单命令
从零单排Linux – 1 – 简单命令 Posted in: Linux 从零单排Linux – 1 一.Linux的简单命令: 1.忘记root密码: 读秒时按任意键进入 – e – ↓选择第二个 ...
- Kafka学习(一)配置及简单命令使用
一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,当中涉及到的相关概念例如以下: Kafka中传递的内容称为message(消息),message 是通过topic ...
- Kafka配置及简单命令使用
一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,其中涉及到的相关概念如下: Kafka中传递的内容称为message(消息),message 是通过topic(话 ...
- Linux的简单命令
Linux的简单命令 1.更改linux服务器的登录密码 成功登录后输入命令: passwd 然后按照提示操作即可 2.在当前路径下新建文件夹:mkdir 新建文件夹名 3.解压和压缩文件tar.gz ...
随机推荐
- Android adb 命令使用总结
adb原理 参考文档 How ADB works http://www.cnblogs.com/ifantastic/p/5186362.html http://blog.csdn.ne ...
- Unity 区分不同平台
问题:公司开发的游戏实在android平台上运行,但是我们是在windows平台下进行开发,OK ,经常有些地方开发完之后就要换到android上面,能区分平台的不同就可以对代码做区分处理 回答:un ...
- JMeter使用点滴
作为一款小巧易用的性能测试工具,JMeter不仅免费开源而且功能强大.易于扩展,如果有一定Java开发基础的话还可以在JMeter上做扩展开发新的插件等,几乎能满足各种性能测试需求,本文用于收集使用J ...
- jwplayer直播
<div class='container'> <div class='row'> <div class='col-sm-10 col-md-10 col-sm-offs ...
- JS初学者必备的几个经典案例(一)!!!
一:选中复选框按钮可用 和 倒计时10秒后按钮可用 这是倒计时10秒后按钮可用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- spring-3-mvc-hello-world-example
http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/
- php配置相关
php.ini error_reporting //配置错误的显示方式 display_errors //此项优先级高于error_reporting,如果关闭该项,会返还http状态码,如果开启,则 ...
- Ubuntu apparmor何方神圣
AppArmor 是一款与SeLinux类似的安全框架/工具,其主要作用是控制应用程序的各种权限,例如对某个目录/文件的读/写,对网络端口的打开/读/写等等. 来之Novell网站的引用: AppAr ...
- Python 虚拟环境Virtualenv
本人也是Python爱好者,众所周知,Python扩展多,每次为了测试,安装各种各样的扩展,这样导致本地的Python环境非常混乱,就有人想到搞个隔离环境 和 本地环境没有关系,随时可以删除这个隔离 ...
- 一段检测IP设备是否在线的代码
原理是通过发送ARP包来检测 uses WinSock function SendARP(const DestIP, SrcIP: Cardinal; pMacAddr: PULONG; var Ph ...