sql语句有关问题,取最大值有关问题

sql语句问题,取最大值问题表结构yd_ls_dbhhdfnysfpc200030932005051200030932005061200030932005071200030

sql语句问题,取最大值问题
表结构     yd_ls_db
hh                 dfny       sfpc
200030932005051
200030932005061
200030932005071
200030932005101
200030932007041
200029942000011
200029942001111
200029942001121
200029942002011
200029942002021
200029942002031
----------------------------
现在我想根据hh     取最大的dfny   的一条记录   ,比如上面的查询结果就是
200030932007041
200029942002031
--------------------------------------------
yd_ls_db   中数据量比较大,基本上在500万左右,我用这个语句
select   *   from   yd_ls_db   where   (hh,dfny)   in   (
select   hh,max(dfny)   dfny   from   yd_ls_db   group   by   hh);
速度非常慢.
用这个语句      
select   hh,dfny,sfpc  
from   (
      select   hh,dfny,sfpc,
            rank()   over   (order   by   dfny   desc)   add_rank
      from   yd_ls_db
)
where   add_rank   =   1;
速度也好不到哪里去,哪个高人指导一下
-----------------------


[解决办法]
把你的in换成exists试试,不能保证能快,和你表的索引设置也有关系,只能试试吧.
select * from yd_ls_db t1 where exists (select 'X ' from
(select hh,max(dfny) dfny from yd_ls_db group by hh )
where hh=t1.hh and dfny=t1.dfny);
[解决办法]
索引建了吗
[解决办法]
这样不行吗
select t.hh,max(t.dfny),max(t.sfpc) from sql_0829 t group by t.hh