ORACLE Top/Bottom N、First/Last、NTile
目录
==================================================================
1.带空值的排列
2.Top/Bottom N查询
3.First/Last排名查询
4.按层次查询
一、带空值的排列:
假如被排列的数据中含有空值呢?
SQL> select region_id, customer_id,
2 sum(customer_sales) cust_sales,
3 sum(sum(customer_sales)) over(partition by region_id) ran_total,
4 rank() over(partition by region_id
5 order by sum(customer_sales) desc) rank
6 from user_order
7 group by region_id, customer_id;
REGION_ID CUSTOMER_ID CUST_SALES RAN_TOTAL RANK
---------- ----------- ---------- ---------- ----------
10 31 6238901 1
10 26 1808949 6238901 2
10 27 1322747 6238901 3
10 30 1216858 6238901 4
10 28
相关文档:
由于系统移植,原来的数据库编码和时区都换了,原来的一些SQL文也出错了。。
经常崩出"ORA-01846: not a valid day of the week
"错误。
经测试,以下这个简单语句也会错!!
SQL> select next_day(sysdate,'FRIDAY') from DUAL;
select next_day(sysdate,'FRIDAY') from DUAL
ORA-01 ......
1.得到一个表的ddl语句:
SET SERVEROUTPUT ON
SET LINESIZE 1000
SET FEEDBACK OFF
set long 999999 ------显示不完整
SET PAGESIZE 1000 ----分页
EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.S ......
今天在一个帖子里看到shiyiwan的回帖中提及到了两个自己以前没见过的概念,save exception和dml error logging。上网搜了搜相关内容,看了看大概明白意思,不过在实际运用中还是没怎么用过。保存下来,以后用的到的话方便查阅。
这一篇是关于save exception的,另外一篇dml error logging的参见如下链接
http://blog.csdn ......
Oracle主键自动增长
这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下:
create table simon_example
(
id number(4) not null primary key,
name varchar2(25)
)
-- 建立序列:
-- Create sequence
create sequence SIMON_SEQUENCE &nb ......
目录
======================================================
1.使用rownum为记录排名
2.使用分析函数来为记录排名
3.使用分析函数为记录进行分组排名
一、使用rownum为记录排名:
【1】测试环境:
SQL> desc user_order;
Name   ......