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

oracle keep(first/last)


 先看一段ORACLE官方文档
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/analysis.htm#25806:
FIRST/LAST Functions
The FIRST/LAST aggregate functions allow you to return the result of an aggregate applied over a set of rows that rank as the first or last with respect to a given order specification. FIRST/LAST lets you order on column A but return an result of an aggregate applied on column B. This is valuable because it avoids the need for a self-join or subquery, thus improving performance. These functions begin with a tiebreaker function, which is a regular aggregate function (MIN, MAX, SUM, AVG, COUNT, VARIANCE, STDDEV) that produces the return value. The tiebreaker function is performed on the set rows (1 or more rows) that rank as first or last respect to the order specification to return a single value.
To specify the ordering used within each group, the FIRST/LAST functions add a new clause starting with the word KEEP.
大意是说FIRST/LAST函数按照某个字段排序后取得第一行或者最后一行,FIRST/LAST聚集函数可以按A列排序,B列聚集,避免了自连接和子查询.分组聚合函数(min,max....)位于FIRST/LAST函数之前产生多行结果集,并且按照排序返回FIRST/LAST单个值.
要指定在每个组的顺序,FIRST/LAST函数之前加上以关键字KEEP开始即可
FIRST/LAST Syntax
These functions have the following syntax:
aggregate_function KEEP
( DENSE_RANK LAST ORDER BY
expr [ DESC | ASC ] [NULLS { FIRST | LAST }]
 [, expr [ DESC | ASC ] [NULLS { FIRST | LAST }]]...)
[OVER query_partitioning_clause]
Note that the ORDER BY clause can take multiple expressions.请注意在ORDER BY子句可以采取多种表现形式
Returns the row ranked first using DENSE_RANK   
2种取值:
DENSE_RANK FIRST
DENSE_RANK LAST
在keep (DENSE_RANK first ORDER BY sl) 结果集中再取max、min的例子。
例子如下:oracle分析函数中,keep and over的区别
公司部门中入厂时间最早的员工的薪水最小的是多少
SQL>SELECT deptno,ename,empno,sal,
MIN(sal) KEEP (dense_rank FIRST ORDER BY hiredate) over (PARTITION


相关文档:

oracle 存储过程

1.创建过程
   与其它的数据库系统一样,Oracle的存储过程是用PL/SQL语言编写的能完成一定处理功能的存储在数据库字典中的程序。
  语法:
  create [or replace] procedure procedure_name
  [ (argment [ { in| in out }] type,
  argment [ { in | out | in out } ] type
  { is | as }
  <类型 ......

oracle管理表空间和数据文件

'
ALTER TABLESPACE app_data
      ADD DATAFILE 'u01/oradata/userdata03.dbf'
SIZE 200M;
'创建表空间
CREATE TABLESPACE userdata
DATAFILE 'u01/oradata/userdata03.dbf' SIZE 100M
AUTOEXTEND ON NEXT 5M MAXSIZE 200M;
'创建回滚表空间
CREATE UNDO TABLESPACE undo1
DATAFILE ' ......

Aix5.3下Oracle 10g设置归档模式到文件系统


新建文件系统
        crfs  -v jfs  -g  rootvg  -m /arch -a \ size=32768 -a frag=512 -a nbpi=8192  也可以 smit。
开启归档模式
     $ sqlplus '/as sysdba'
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Dec 10 13:38 ......

玩转Oracle(4)

//使用自定义函数定义日期格式
to_date('1982-11-11','yyyy-mm-dd')
to_date('1982/11/11','yyyy/mm/dd')
//希望员工scott的岗位,工资,补助与smith员工一样
update emp set (job,sal,comm)=(select job,sal,comm from emp where ename='SMITH') where ename='SCOTT';
||-------  java使用oracle &nbs ......

Oracle临时表的建立及使用....

在Oracle8i或以上版本中,可以创建以下两种临时表:    
  1。会话特有的临时表    
          CREATE   GLOBAL   TEMPORARY   <TABLE_NAME>   (<column   specification>)    
        &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号