-- 查找两个表中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 的简单命令之三的更多相关文章

  1. PLSQL 的简单命令之五

    --1. 查询和Zlotkey相同部门的员工姓名和雇用日期 select a.last_name,a.hire_date ,b.department_name from employees a,dep ...

  2. PLSQL 的简单命令之四

    -- 子查询 -- in 等于表中的任意一个 select * from Stu where id in (select id from scores) -- 和子查询返回结果中的某一个值比较成立即可 ...

  3. PLSQL 的简单命令之二

    --1. 查询工资大于12000的员工姓名和工资 --2. 查询员工号为176的员工的姓名和部门号 ' --3. 选择工资不在5000到12000的员工的姓名和工资 --4. 选择雇用时间在1998- ...

  4. Apache 的搭建及vim的简单命令

    一. vim 简单命令 pwd     当前路径 ls    当前路径所有目录 cd  目录地址   跳转到指定目录 /xxx  查找xxx x 删除当前字符 n 执行上一次查找 二.为什么使用apa ...

  5. ORACLE的安装与网页版创建表空间的简单操作以及PLsql的简单操作

    1.oracle的安装: 安装简单易学,在这里不做解释.下载看装包后耐心等待,注意安装目录不要有中文字符,尽量按照指定目录进行安装.安装完成后会占用有大约5g的内存. 如果要卸载oracle,需要用其 ...

  6. 从零单排Linux – 1 – 简单命令

    从零单排Linux – 1 – 简单命令 Posted in: Linux 从零单排Linux – 1 一.Linux的简单命令: 1.忘记root密码: 读秒时按任意键进入 – e – ↓选择第二个 ...

  7. Kafka学习(一)配置及简单命令使用

    一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,当中涉及到的相关概念例如以下: Kafka中传递的内容称为message(消息),message 是通过topic ...

  8. Kafka配置及简单命令使用

    一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,其中涉及到的相关概念如下: Kafka中传递的内容称为message(消息),message 是通过topic(话 ...

  9. Linux的简单命令

    Linux的简单命令 1.更改linux服务器的登录密码 成功登录后输入命令: passwd 然后按照提示操作即可 2.在当前路径下新建文件夹:mkdir 新建文件夹名 3.解压和压缩文件tar.gz ...

随机推荐

  1. 【翻译】Kinect v1和Kinect v2的彻底比较

      本连载主要是比较Kinect for Windows的现行版(v1)和次世代型的开发者预览版(v2),以C++开发者为背景介绍进化的硬件和软件.本文主要是对传感的配置和运行条件进行彻底的比较.   ...

  2. zero cycles - 1 to 30 cycles - tens of millions of cycles

    Computer Systems A Programmer's Perspective Second Edition To this point in our study of systems, we ...

  3. MySQL 绿色版(zip) 安装

    设置环境变量Path,指向到MYSQL下的bin目录 修改MYSQL下的my-default.ini basedir=%MYSQL_HOME% datadir=%MYSQL_HOME%\data 到M ...

  4. Ubuntu/Deepin下常用软件汇总(持续更新)

    最近开始用Ubuntu了,好多软件都不是常用的了,在这边留底,以免忘记.如果没有写安装方法,则直接在软件源中可以找到 UNetbootin U盘制作工具,制作Ubuntu的安装U盘超好用 Braser ...

  5. java.util.concurrent.CopyOnWriteArrayList

    import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; impo ...

  6. This application failed to start because it could not find or load the Qt platform plugin "xcb".

    1.  copy      libQt5DBus.so.5 2.  add    QT_PLUGIN_PATH blog.csdn.net/windows_nt/article/details/242 ...

  7. 基于ace后台管理系统模板--CMS(Thinkphp框架)的筹划

    临近春节,准备自己做一个关于宠物的cms网站,特写下此博客提醒自己,尽量争取在过年前做好.废号少说,先梳理下接下来准备使用的工具.. 由于最近在学习thinkphp,所以打算用这个框架来作为主体,可能 ...

  8. 关于<a href='javascript:function()'>

    <a href='javascript:function()'> 这样写是为了让这个链接不要链接到新页面转而执行一段js代码.和onclick能起到同样的效果,一般来说,如果要调用脚本还是 ...

  9. 自己写的一个DirectUI库,基础控件基本都已实现

    http://download.csdn.net/detail/pcradio/9254881 http://blog.csdn.net/pcradio

  10. gridcontrol中使用右健菜单popupMenu1

    private void gridView1_ShowGridMenu(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs ...