数据结构是这个样子的:
ID Date1 name date2 re
10 2010-11-22 16:43:31 A44 2010-11-23 15:53:48 国际大方大方好
11 2010-11-22 16:40:30 A33 2010-11-23 15:59:53 不愿意审批
12 2010-11-22 16:40:30 A33 2010-11-23 16:03:00 0000000000000
13 2010-11-30 9:44:37 SS1 2010-11-30 9:59:40 111111111111
14 2010-11-30 9:42:54 SS2 2010-11-30 10:37:04 2222222222222
15 2010-11-30 9:46:22 SS3 2010-11-30 10:56:59 3333333333333
16 2010-11-22 16:40:30 A33 2010-11-23 15:48:10 "11111111111
17 2010-11-22 16:40:30 A33 2010-11-23 15:51:21 12341234
需要的数据是:
10 2010-11-22 16:43:31 A44 2010-11-23 15:53:48 国际大方大方
12 2010-11-22 16:40:30 A33 2010-11-23 16:03:00 0000000000000
13 2010-11-30 9:44:37 SS1 2010-11-30 9:59:40 11111111111
14 2010-11-30 9:42:54 SS2 2010-11-30 10:37:04 22222222222
15 2010-11-30 9:46:22 SS3 2010-11-30 10:56:59 333333333333
选择时间最大的重复姓名的的数据.
ID Date1 name date2 re
10 2010-11-22 16:43:31 A44 2010-11-23 15:53:48 国际大方大方好
11 2010-11-22 16:40:30 A33 2010-11-23 15:59:53 不愿意审批
12 2010-11-22 16:40:30 A33 2010-11-23 16:03:00 0000000000000
13 2010-11-30 9:44:37 SS1 2010-11-30 9:59:40 111111111111
14 2010-11-30 9:42:54 SS2 2010-11-30 10:37:04 2222222222222
15 2010-11-30 9:46:22 SS3 2010-11-30 10:56:59 3333333333333
16 2010-11-22 16:40:30 A33 2010-11-23 15:48:10 "11111111111
17 2010-11-22 16:40:30 A33 2010-11-23 15:51:21 12341234
需要的数据是:
10 2010-11-22 16:43:31 A44 2010-11-23 15:53:48 国际大方大方
12 2010-11-22 16:40:30 A33 2010-11-23 16:03:00 0000000000000
13 2010-11-30 9:44:37 SS1 2010-11-30 9:59:40 11111111111
14 2010-11-30 9:42:54 SS2 2010-11-30 10:37:04 22222222222
15 2010-11-30 9:46:22 SS3 2010-11-30 10:56:59 333333333333
选择时间最大的重复姓名的的数据.
解决方案 »
- SQL行转列问题求解,实在是想不出解决办法了,请高手们帮忙!谢谢!
- IMP-00020: 用于列缓冲区大小 (6) 的长整数列过大
- 请问如何检测oracle里面的索引和存储过程是否失效
- DBConsole 服务启动问题???
- 基础问题,这样的语句怎么优化
- 用用户user1建立两个表空间后,如何分别查询出每个表空间各自有多少个用户表呢?
- 写个触发器
- 紧急在线求助:如何写这样的存储过程?
- 导数据库文件问问题
- 求问!oracle8.17的几个菜鸟问题?俺现在只有50分!在线等待!!!!
- odbc SQLBindParameter oracle date字段插入 100分
- 困惑,java中抛出的oracle异常
select ID,Date1,name,date2,re
from (select ID,Date1,name,date2,re,row_number() over(partition by name order by date2) rn
from tb)
where rn=1
select ID,Date1,name,date2,re
from (select ID,Date1,name,date2,re,row_number() over(partition by name order by date2 desc) rn
from tb)
where rn=1
select * from tb t
where date2=(select max(date2) from tb where t.name=name);
select 10 ID,to_date('2010-11-22 16:43:31','yyyy-mm-dd hh24:mi:ss') Date1,'A44' name,
to_date('2010-11-23 15:53:48','yyyy-mm-dd hh24:mi:ss') date2,'国际大方大方好' re
from dual union all
select 11,to_date('2010-11-22 16:40:30','yyyy-mm-dd hh24:mi:ss'),'A33',
to_date('2010-11-23 15:59:53','yyyy-mm-dd hh24:mi:ss'),'不愿意审批' from dual union all
select 12,to_date('2010-11-22 16:40:30','yyyy-mm-dd hh24:mi:ss'),'A33',
to_date('2010-11-23 16:03:00','yyyy-mm-dd hh24:mi:ss'),'0000000000000' from dual union all
select 13,to_date('2010-11-30 9:44:37','yyyy-mm-dd hh24:mi:ss'),'SS1',
to_date('2010-11-30 9:59:40','yyyy-mm-dd hh24:mi:ss'),'111111111111' from dual union all
select 14,to_date('2010-11-30 9:42:54','yyyy-mm-dd hh24:mi:ss'),'SS2',
to_date('2010-11-30 10:37:04','yyyy-mm-dd hh24:mi:ss'),'2222222222222' from dual union all
select 15,to_date('2010-11-30 9:46:22','yyyy-mm-dd hh24:mi:ss'),'SS3',
to_date('2010-11-30 10:56:59','yyyy-mm-dd hh24:mi:ss'),'3333333333333' from dual union all
select 16,to_date('2010-11-22 16:40:30','yyyy-mm-dd hh24:mi:ss'),'A33',
to_date('2010-11-23 15:48:10','yyyy-mm-dd hh24:mi:ss'),'11111111111' from dual union all
select 17,to_date('2010-11-22 16:40:30','yyyy-mm-dd hh24:mi:ss'),'A33',
to_date('2010-11-23 15:51:21','yyyy-mm-dd hh24:mi:ss'),'12341234' from dual)
--以上为提供数据的语句
select ID,Date1,name,date2,re
from (
select ID,Date1,name,date2,re,row_number() over(partition by name order by date2 desc) rn
from tb
)
where rn=1 ID DATE1 NAM DATE2 REMARK
---------- -------------- --- -------------- --------------
12 22-11月-10 A33 23-11月-10 0000000000000
10 22-11月-10 A44 23-11月-10 国际大方大方好
13 30-11月-10 SS1 30-11月-10 111111111111
14 30-11月-10 SS2 30-11月-10 2222222222222
15 30-11月-10 SS3 30-11月-10 3333333333333