select A,B=(select B from 表名 where C=max(a.C)),max(C) from 表名 a group by A ;
解决方案 »
- oracle 查询单列转单行
- Oracle的https://localhost:1158/em IE不能登入
- 求救一個select連續n天的語句
- 装Oracle时遇到的问题,请帮忙看看,谢谢!
- oracle update 更新多字段用一条sql 的预设默认值的问题
- 急问 ORACLE 中能用opendatasource吗?我要在一条运行在ORACLE中的SQL语句将ORACLE中一个表中的数据导入到硬盘中的一个ACCESS表中去!!
- PLSQL 查询不到数据
- 我用PL\SQL Developer,怎么Number太长,他总是用科学计数法.有没有办法不这样?
- oracle9i的主机改计算机名称后,无法访问...
- SQL基础问题,四个sql语句的效率有什么区别?
- 我遇到了toad的启动问题,toad一闪就没了
- 隐式游标的问题?
where r.rk=1;
select * from tbname a where a.C =(select max(b.C) from tbname b where a.A=b.A)
--建表
create table tn(A int,B int,C int);
insert into tn select 1, 2, 4 from dual
union all select
1, 2, 3
from dual
union all select
2 ,3, 4
from dual
union all select
3 ,3, 5
from dual;--测试
select * from tn where C in (select max(C)from tn a group by A);--结果 A B C
---------- ---------- ----------
1 2 4
2 3 4
3 3 5
其他人的我没看,就yjdn(无尽天空)的答案,齐是一下子就看出来有问题了,最简单的例子,再增加一条记录
INSERT INTO TN(A,B,C) VALUES('4','3','3'),你看结果是什么?是不是五条记录全出来了
其实很简单了只要 SELECT A,B,MAX(C) FROM TN GROUP BY A,B 就可以了,但这样会出现C最大,B不同,A重复的问题。
select * from tbname a where a.C =(select max(b.C) from tbname b where a.A=b.A) select a,b,c from (select a,b,c,sum(1) over(partition by a order by c desc) num from t4) tmp where tmp.num=1;
from (select a,max(c) c from table group by a) t1,table t2
where t1.a=t2.a and
t1.c=t2.c;
方法一:
select a,b,c from (select a,b,c,rank() over(partition by a order by c desc) rank from tab ) t
where t.rank=1;
方法二:
select k.a,t.b,k.c from (select a,max(c) c from tab group by a) k,tab t where t.c=k.c and t.a=k.a;