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 ...
随机推荐
- 彻底搞清楚字符编码: ASCII, ISO_8859, GB2312,UCS, Unicode, Utf-8
彻底搞清楚字符编码: ASCII, ISO_8859, GB2312,UCS, Unicode, U 1.ASCII: 0-127(128-255未使用),美国标准 2.IS0-8859-1(lati ...
- [办公自动化]windows7 仿宋GB2312字体打印不对
今天同事发现自己的文档中,仿宋GB2312这种字体打印的看着总觉得不对. 他使用的操作系统是windows7,office 是2007. 解决方案: 将windows xp中的c:\windows\f ...
- 做了一个简易的git 代码自动部署脚本
做了一个简易的git 代码自动部署脚本 http://my.oschina.net/caomenglong/blog/472665 发表于2个月前(2015-06-30 21:08) 阅读(200 ...
- Unity 为NGUI增加体感输入方式
背景 NGUI在处理UI和输入方面确实做的不错,但是现在的问题是公司引入体感之后,是通过手的位置来实现按钮的点击操作,前提我不想改变原先设计好的NGUI界面和机制,怎么破? NGUI的输入底层机制 N ...
- P1083 借教室
思路:前缀和, c表示对于当前的middle, 前缀和 #include <bits/stdc++.h> using namespace std; const int maxn = 1e6 ...
- PureBasic 读取文件中一行的两个数据例子
, "Test1.txt") ; if the file could be read, we continue... , "Test2.txt") ) = ; ...
- (转)面试题--JAVA中静态块、静态变量加载顺序详解
public class Test { //1.第一步,准备加载类 public static void main(String[] args) { new Test(); //4.第四步,new一个 ...
- PDO知识
PDO: 一.含义: 数据访问抽象层 二.作用 :通过PDO能够访问其它的数据库 三. 用法: 1.造对象 ①$dsn="mysql:dbname=zz;host=localhost&quo ...
- C# IO操作,写入文本到txt文件.
/// <summary> /// 写入日志文件 /// </summary> /// <param name="input"></par ...
- graphviz - Node Shapes
Node Shapes There are three main types of shapes : polygon-based, record-based and user-defined. The ...