不用order 不用连接 select * from 你的表 tem where 第一列=(select max(第一列) from 你的表 where 第二列=tem.第二列)
我试过了,绝对可以用。接分 create table temp (id number, shu number, zi number )insert into table temp values(1,20,40); insert into table temp values(2,20,41); insert into table temp values(3,50,44); insert into table temp values(4,50,45);select * from temp; ID SHU ZI ---------- ---------- ---------- 1 20 40 2 20 41 3 50 44 4 50 45select * from temp a,temp b where a.shu= b.shu and a.zi>b.zi ID SHU ZI ID SHU ZI ---------- ---------- ---------- ---------- ---------- ---------- 2 20 41 1 20 40 4 50 45 3 50 44就这样,你的要求达到了。
子查询里可以用Order by , 但必需用 top n 一般n取足够大的数,大于你子查询返回的行数即可!
例如表结构如下: 表名:test AA BB ------- 20 40 20 41 50 43 50 2 50 3SELECT test.AA,max(BB) from test, (SELECT aa FROM test GROUP BY aa) tmp WHERE test.AA=tmp.AA GROUP BY test.AA检索结果: 20 43 50 3
上面那个有个地方笔误。 例如表结构如下: 表名:test AA BB ------- 20 40 20 41 20 43 50 2 50 3SELECT test.AA,max(BB) from test, (SELECT aa FROM test GROUP BY aa) tmp WHERE test.AA=tmp.AA GROUP BY test.AA检索结果: 20 43 50 3
晕,下面的语句足够了 SELECT AA,MAX(BB) FROM TEST GROUP BY AA;检索结果: 20 43 50 3
to 玩命聊: 你那样做就太简单了,楼主的意思并不是要你把数据查出来,他的意思是举个例子问能否使用ORDER BY! 同意 用泪水灌溉幸福的观点,我在书上也看到的,只是这种用法好象一般用处不大。很少使用。
rownum是在order by 之前确定的,因此要得到order by 之后的rownum必须再套一层子查询。
表名:test AA BB ------- 20 40 20 41 50 43 50 2 50 3select * from (select a.*,rank() over(partition by aa order by bb desc) rk from test a) where rk=1
I hope it can help you http://www.csdn.net/develop/read_article.asp?id=21371order by in the sub query is not supported in lower oracle version
select id,aa,bb from b where rowid=(select max(rowid) from b tt where tt.aa=b.aa);
不用连接
select * from 你的表 tem where 第一列=(select max(第一列) from 你的表 where 第二列=tem.第二列)
create table temp
(id number,
shu number,
zi number
)insert into table temp values(1,20,40);
insert into table temp values(2,20,41);
insert into table temp values(3,50,44);
insert into table temp values(4,50,45);select * from temp;
ID SHU ZI
---------- ---------- ----------
1 20 40
2 20 41
3 50 44
4 50 45select * from temp a,temp b
where a.shu= b.shu
and a.zi>b.zi
ID SHU ZI ID SHU ZI
---------- ---------- ---------- ---------- ---------- ----------
2 20 41 1 20 40
4 50 45 3 50 44就这样,你的要求达到了。
但必需用 top n
一般n取足够大的数,大于你子查询返回的行数即可!
表名:test
AA BB
-------
20 40
20 41
50 43
50 2
50 3SELECT test.AA,max(BB) from test,
(SELECT aa FROM test
GROUP BY aa) tmp
WHERE test.AA=tmp.AA
GROUP BY test.AA检索结果:
20 43
50 3
例如表结构如下:
表名:test
AA BB
-------
20 40
20 41
20 43
50 2
50 3SELECT test.AA,max(BB) from test,
(SELECT aa FROM test
GROUP BY aa) tmp
WHERE test.AA=tmp.AA
GROUP BY test.AA检索结果:
20 43
50 3
SELECT AA,MAX(BB)
FROM TEST
GROUP BY AA;检索结果:
20 43
50 3
你那样做就太简单了,楼主的意思并不是要你把数据查出来,他的意思是举个例子问能否使用ORDER BY!
同意 用泪水灌溉幸福的观点,我在书上也看到的,只是这种用法好象一般用处不大。很少使用。
AA BB
-------
20 40
20 41
50 43
50 2
50 3select * from
(select a.*,rank() over(partition by aa order by bb desc) rk from test a)
where rk=1
http://www.csdn.net/develop/read_article.asp?id=21371order by in the sub query is not supported in lower oracle version
where rowid=(select max(rowid) from b tt where tt.aa=b.aa);