读书人

不用游标能解决这个有关问题么

发布时间: 2012-01-18 00:23:26 作者: rapoo

不用游标能解决这个问题么?
select a.pono,b.part,a.date from a , b , c where
a.pono=b.pono and b.part in ( '30804001 ', '30804003 ', '30804004 ') and b.part=c.part ;
每一个part都有多个pono,你说我想求时间最大的那个pono,除了用游标还有别的方法没有。
我用游标的主要步骤是这么写的 , :
select part from c where part in '30804001 ', '30804003 ', '30804004 ') ;
open mypur;
loop
fetch mypur into as_part;
exit when mypur %notfound;
select pono,reldate,part,description,unit,unprc
from (select a.pono,a.date,b.part,c.description,b.unit,b.unprc from
a , b , c where
a.pono=b.pono and b.part=as_part and b.part=c.part
order by a.reldate desc ) where rownum=1 ;
end loop;

谁有更好的方法解决速度问题,我用SQL SERVER就是用游标作的,可oracle用游标速度太慢了!大家还有别的思想么

[解决办法]
SQL> select * from t;

ID NAME NUM
---------- -------------------- ----------
1 wzk 3
2 fg 3
3 zx 4
3 cc 5
2 gg 6

SQL> select id,max(name) m_n from t group by id;

ID M_N
---------- --------------------


1 wzk
2 gg
3 zx

SQL> select t.id,t.name,t.num from t,(select id,max(name) m_n from t group by id) b
2 where t.id= b.id and t.name = b.m_n;

ID NAME NUM
---------- -------------------- ----------
1 wzk 3
2 gg 6
3 zx 4

SQL>

读书人网 >oracle

热点推荐