解决方案 »
- 在查询中怎么做到只要查到结果马上返回?
- oracle高手请进!!求教不定行转列建视图的问题
- oracle客户端与服务器端字符集不一致,修改客户端,服务器启动失败
- 求oracle 下载地址!
- 我装有两个OS,在简体的win2003上装了个oracle9,发现在OEM里包错的框里的汉字都变成了????,有社么办法吗?
- 如何写查询从2003-12-1到2003-12-9的SQL语句?
- 怎么从一个表空间来另一个表空间
- 救救小弟,dbsnmp问题,在线等待!!!
- oracle中一个date类型的变量占用几个字节?
- 各位前辈,我想求一个绝对值的写法
- 谁能提供个查sga还剩多少可用空间的sql,谢谢
- 问两个SQL语句的区别
where not exists (select 1 from (select column1,column2,max(date1) date1 from table_name) b
where a.column1=b.column1 and a.column2=b.column2 and a.date1=b.date1)
不好意思,少了group by
delete from table_name a
where not exists (select 1 from (select column1,column2,max(date1) date1 from table_name group by column1,column2) b
where a.column1=b.column1 and a.column2=b.column2 and a.date1=b.date1)
delete from ttt
where rowid not in (select rowid
from (select id,
id1,
date1,
row_number() over(partition by id, id1 order by id, id1, date1 desc) rn
from ttt)
where rn = 1)
--row_number() over()来
select 字段1,字段2,字段3
(select 字段1,字段2,字段3,row_number() over(partition by 字段1,字段2 order by 字段3) rn
from tb) a
where rn=1
--2
select * from tb a
where 字段3 in(select max(字段3) from tb
where a.字段1=字段1 and a.字段2=字段2 group by 字段1,字段2)--3
select * from tb a
where exists(select 1 from tb where a.字段1=字段1 and a.字段2=字段2 and a.字段3>字段3 )
From mytable
Group by col1, col2;不就行了吗?
select *
from tmp t1
where rowid =
(
select max(rowid)
from tmp t2
where t1.id = t2.id and t1.name = t2.name
)
为什么没人指出Group by col1, col2这部分的明显错误呢?,完全说不通的写法。(勋章?假的吧!)
row_number()在ORACLE里是存在的2
这个group by是有些问题 应该是没看清题意疏忽了吧 呵呵
表1
字段1 字段2 字段3
a t1 2010-5-5 15:23:30
b tp 2010-5-5 15:23:30
c tk 2010-5-5 15:23:30
d ty 2010-5-5 15:23:30我的理解是这个表有三列,第一、第二都是字符型,第三列是日期(当然包含时间),所以我给出的query得出的结果就是贴主要求的。
如果贴主告诉我第一列包含象"a t1"这样的字符,而第二第三列分别是日期和时间,那我必须承认我的想象力不够,无法理解表还能这么设计的。另外回楼上的,使用rowid之前必须先理解rowid到底是个什么东西,它只是记录的物理地址,Oracle从来不保证它能用于替代任何基于业务逻辑的排序(比如日期列),所以是不能用于这个例子的。
select max(字段3),字段1,字段2 from 表1 group by 字段1,字段2