over partition簡單使用
今天在網上看到的over partition簡單使用
http://www.itpub.net/thread-1940278-1-1.html
create table T1
(
id VARCHAR2(10),
appid VARCHAR2(10),
key VARCHAR2(10),
version VARCHAR2(64),
result VARCHAR2(10),
create_date DATE
);
insert into T1 (id, appid, key, version, result, create_date) values ('1', '1', 'ABC', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('18-10-2015 11:10:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('2', '1', 'BCD', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('18-10-2015 11:20:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('3', '1', 'CDE', '9CE5B7149CDB852BC3AE1F7191920E9E', '0', to_date('18-10-2015 11:30:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('4', '1', 'DEF', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('18-10-2015 12:40:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('5', '1', 'EFG', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('18-10-2015 12:50:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('6', '1', 'ABC', 'EE5A53962E9E26BBA230E253FB6A9B29', '1', to_date('17-10-2015 12:01:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('7', '1', 'BCD', 'EE5A53962E9E26BBA230E253FB6A9B29', '0', to_date('17-10-2015 12:20:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('8', '1', 'CDE', 'EE5A53962E9E26BBA230E253FB6A9B29', '1', to_date('17-10-2015 12:30:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('9', '1', 'DEF', 'EE5A53962E9E26BBA230E253FB6A9B29', '0', to_date('17-10-2015 12:40:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('10', '1', 'CDE', 'EE5A53962E9E26BBA230E253FB6A9B29', '1', to_date('17-10-2015 12:41:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('11', '1', 'ABC', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('19-10-2015 11:10:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('12', '1', 'BCD', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('19-10-2015 11:20:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('13', '1', 'CDE', '9CE5B7149CDB852BC3AE1F7191920E9E', '0', to_date('19-10-2015 11:30:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('14', '1', 'DEF', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('19-10-2015 12:40:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('15', '1', 'EFG', '9CE5B7149CDB852BC3AE1F7191920E9E', '1', to_date('19-10-2015 12:50:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('16', '1', 'ABC', 'EE5A53962E9E26BBA230E253FB6A9B29', '1', to_date('20-10-2015 12:01:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('17', '1', 'BCD', 'EE5A53962E9E26BBA230E253FB6A9B29', '0', to_date('20-10-2015 12:20:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('18', '1', 'CDE', 'EE5A53962E9E26BBA230E253FB6A9B29', '1', to_date('20-10-2015 12:30:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('19', '1', 'DEF', 'EE5A53962E9E26BBA230E253FB6A9B29', '0', to_date('20-10-2015 12:40:02', 'dd-mm-yyyy hh24:mi:ss'));
insert into T1 (id, appid, key, version, result, create_date) values ('20', '1', 'CDE', 'EE5A53962E9E26BBA230E253FB6A9B29', '1', to_date('20-10-2015 12:41:02', 'dd-mm-yyyy hh24:mi:ss'));
select * from (select t1.*,row_number() over (partition by key order by create_date desc) rn from t1 where result=1) where rn=1 -->按照key匪類,時間倒序排列,取result=1的值。
ID APPID KEY VERSION RESULT CREATE_DATE RN
1 16 1 ABC EE5A53962E9E26BBA230E253FB6A9B29 1 2015/10/20 12:01:02 1
2 12 1 BCD 9CE5B7149CDB852BC3AE1F7191920E9E 1 2015/10/19 11:20:02 1
3 20 1 CDE EE5A53962E9E26BBA230E253FB6A9B29 1 2015/10/20 12:41:02 1
4 14 1 DEF 9CE5B7149CDB852BC3AE1F7191920E9E 1 2015/10/19 12:40:02 1
5 15 1 EFG 9CE5B7 149CDB852BC3AE1F7191920E9E 1 2015/10/19 12:50:02 1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-1814889/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- over (partition by)
- OVER(PARTITION BY)函式用法函式
- Oracle使用over()partition by刪除重複記錄Oracle
- ROWNUMBER() OVER( PARTITION BY COL1
- 語法:OVER(PARTITION BY)及開窗函式函式
- 理解了row_number()over (partition by order by )的方法
- sql(oracle)資料處理實用總結開窗函式(over partition)使用SQLOracle函式
- row_number() OVER (PARTITION BY COL1 ORDER BY COL2)
- (轉)Oracle語法之OVER(PARTITION BY)及開窗函式Oracle函式
- oracle的分析函式over(Partition by...) 及開窗函式Oracle函式
- Oracle 語法之 OVER (PARTITION BY ..) 及開窗函式 轉載Oracle函式
- Oracle 中分析函式用法之--rank(),dense_rank(),partition,over()Oracle函式
- Oracle統計分析函式集,over(partition by..) 的運用Oracle函式
- 從簡單的快速排序說起-Partition-ThreePartition-TopK排序TopK
- MYSQL-實現ORACLE- row_number() over(partition by ) 分組排序功能.MySqlOracle排序
- Oracle over()函式使用Oracle函式
- Oracle9i中分割槽Partition的使用簡介Oracle
- 簡單使用 rocketmqMQ
- GCDAsyncSocket 簡單使用GC
- JPTabBar簡單使用tabBar
- Quartz 簡單使用quartz
- Github 簡單使用Github
- gorm 簡單使用GoORM
- ListView簡單使用View
- GCD簡單使用GC
- 簡單,使用WKWebViewWebView
- git簡單使用Git
- sftp簡單使用FTP
- redux簡單使用Redux
- jq 簡單使用
- hive dynamic partition的使用Hive
- hive中partition如何使用Hive
- Kdevelop的簡單使用和簡單除錯dev除錯
- prometheus 簡單使用及簡單 middleware 開發Prometheus
- butterfly簡單使用教程
- docker的簡單使用Docker
- postman的簡單使用Postman
- RecyclerView的簡單使用View