oracle分析函式row number

2021-04-18 18:25:03 字數 1666 閱讀 1343

如:一張tmaterialmodify表 字段 objid,materialid(備件id),code(備件編號),name(備件名稱),modifytime(datetime型別) 修改時間 objid 唯一標識列 資料: '1233','11111','a','螺帽','2007-01-01 18:00:00' '1234','22222','b','車蓋','2008-02-04 08:00:00' '1235','11111','a','螺帽','2008-04-01 17:00:00' '1236','11111','a','螺帽','2006-07-11 11:30:00' '1237','22222','b','車蓋','2005-03-02 16:00:00' '1238','22222','b','車蓋','2007-01-01 18:00:00' '1239','22222','b','車蓋','2006-11-01 13:00:00' '1240','11111','a','螺帽','2004-01-01 18:00:00' ........ 想要得結果是顯示在乙個時間段內每個備件最近修改的三條記錄 查詢從修改時間 2006-6-30 00:00:00 ----2008-04-30 00:00:00 的備件修改記錄 結果 '1236','11111','a','螺帽','2006-07-11 11:30:00' '1233','11111','a','螺帽','2007-01-01 18:00:00' '1235','11111','a','螺帽','2008-04-01 17:00:00' '1239','22222','b','車蓋','2006-11-01 13:00:00' '1238','22222','b','車蓋','2007-01-01 18:00:00' '1234','22222','b','車蓋','2008-02-04 08:00:00'

sql:>select * from (select t.*,row_number() over (partition by materialid order by modifytime desc) rn from tmaterialmodify t where t.modifytime between to_date('2006-6-30','yyyy-mm-dd') and to_date('2008-09-30','yyyy-mm-dd')) where rn <=3 /

row_number() over (partition by col1 order by col2) 表示根據col1分組,在分組內部根據 col2排序 而這個值就表示每組內部排序後的順序編號(組內連續的唯一的) 表內容如下: name | seqno | description a | 1 | test a | 2 | test a | 3 | test a | 4 | test b | 1 | test b | 2 | test b | 3 | test b | 4 | test c | 1 | test c | 2 | test c | 3 | test c | 4 | test 我想有乙個sql語句,搜尋的結果是 a | 1 | test a | 2 | test b | 1 | test b | 2 | test c | 1 | test c | 2 | test 實現: select name,seqno,description from(select name,seqno,description,row_number()over(partition by name order by seqno)id from table_name) where id<=3;

oracle分析函式

oracle分析函式 sql plus環境 1 group by子句 create test table and insert test data.create table students id number 15,0 area varchar2 10 stu type varchar2 2 sc...

Oracle 分析函式

分析函式提供了跨行,多層級聚合引用值的能力,並且可以在資料子集中控制排序粒度。與聚合函式不同,分析函式並不將結果集聚合較少的行。分析函式是在主查詢結果的基礎上進行一定的分析,如分部門彙總,分部門求均值等等。分析函式的模式 function arg1,arg2,arg3.argn over parti...

oracle 分析函式 排序值分析函式

一 問題描述 查詢列表時,我們有時需要對查詢結果依據某個字段進行排名。如果每條記錄在排序欄位上都不相同,我們可以將原查詢作為乙個檢視,查詢其rownum,便可以實現簡單排序,例如 但是,很多時候我們想用來排序的字段都是有重複值的,此時可能需要將值相同的記錄名詞並列,那麼我們就需要用到oracle的分...