易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle 多表连接子查询

1.求部门中哪些人薪水最高:
select ename,sal
from emp join
(
    select max(sal) max_sal, deptno
    from emp
    group by deptno
) t
on (emp.sal = t.max_sal and emp.deptno = t.deptno);
2.求部门平均薪水的等级:
select deptno, avg_sal, grade
from
(
    select deptno, avg(sal) avg_sal
    from emp
    group by deptno
) t join salgrade s
on (t.avg_sal between s.losal and s.hisal);
3.求部门平均的薪水等级:
select deptno, avg(grade)
from (
    select deptno, ename, grade
    from emp join salgrade s
    on emp.sal between s.losal and s.hisal
) t
group by deptno;
4.求哪些人是经理人:
select ename from emp where empno in (select distinct mgr from emp);
5.不准用聚集函数,求薪水的最高值:
select distinct sal
from emp
where sal not in
(
    select distinct e1.sal
    from emp e1 join emp e2 on (e1.sal < e2.sal)
);
6.求平均薪水最高部门的部门编号:
select deptno, avg_sal
from (
    select deptno, avg(sal) avg_sal
    from emp
    group by deptno
) where avg_sal = (
    select max(avg_sal)
    from (
        select deptno, avg(sal) avg_sal
        from emp
        group by deptno
    )
);
7.求平均薪水最高部门的部门名称:
select deptno,dname
from dept
where deptno = (
    select deptno
    from (
        select deptno, avg(sal) avg_sal
        from emp
        group by deptno
    ) where avg_sal = (
        select max(avg_sal)
     


相关文档:

学习《Oracle 9i10g编程艺术》的笔记 (八) 内存结构

 Oracle  3 个主要的内存结构:
系统全局区(System Global Area,SGA):这是一个很大的共享内存段,几乎所有Oracle
进程都要访问这个区中的某一点。
进程全局区(Process Global Area,PGA):这是一个进程或线程专用的内存,其他进程/
线程不能访问。
用户全局区(User Global Area,UGA):这个内存区与 ......

Oracle 的drop table if exists功能

Oracle创建表时,常遇到先删除后创建的情况,而它又没有drop table... if exists语法。为此可以使用user_objects数据字典和动态sql语句实现类似的功能,如下所示:
create or replace procedure proc_dropifexists(
    p_table in varchar2
) is
    v_count number(10);
begin
&nbs ......

Oracle sqlplus 配置

sqlplus的配置文件为login.sql,通常如下所示创建该文件:
set serveroutput on size 1000000
set trimspool on  --滤除spool输出的空白
set linesize 200  --用于设定每行显示的宽度
set pagesize 9999 --设置显示的页数
set sqlprompt '_user @ _connect_identifier> '
将该文件复制到Oracle安装目录C ......

Oracle 转义字符

一、准备特殊数据
create table t_escape(s varchar2(50));
--show define -- define "&" (hex 26)
--show escape -- escape off
set define off
set escape on
insert into t_escape values('string&text');
insert into t_escape values('string\&text');
insert into t_escape values('st ......

oracle字符集修改问题

 1:重新在dbca中创建数据库并选择正确的字符集
2:
查询当前字符集:
select userenv('language') from dual;
select * from V$NLS_PARAMETERS;
在Windows下sqlplus完全正常,可是到Linux下,sqlplus中文显示就出问题了,总是显示“??”,这个问题又怎么解决呢?
经过在网络上查资料,以及尝试,得到 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号