ORACEL的分析函数:可以取出分组中第一个(最后一个)的数据
first_value() over(partition by ... order by ...)
last_value() over(partition by ... order by ...)
create table ATEM
(
CO1 VARCHAR2(10),
CO2 INTEGER
)
insert into atem(co1,co2) values('a',1);
insert into atem(co1,co2) values('a',2);
insert into atem(co1,co2) values('a',3);
insert into atem(co1,co2) values('a',4);
insert into atem(co1,co2) values('a',1);
insert into atem(co1,co2) values('b',1);
insert into atem(co1,co2) values('b',2);
insert into atem(co1,co2) values('c',1);
insert into atem(co1,co2) values('d',1);
insert into atem(co1,co2) values('d',2);
select distinct(FIRST_VALUE(a.co2)OVER(PARTITION BY a.co1 ORDER BY a.co2)) as co2,a.co1
from atem a
// FIRST_VALUE(a.co2)OVER(PARTITION BY a.co1 ORDER BY a.co2)
//在表中以a.co1分组,并在分组中以a.co2排序,最后要得到分组中a.co2的数据
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chenjing0718/archive/2007/09/09/1777833.aspx