表结构 yd_ls_db
hh dfny sfpc
20003093 200505 1
20003093 200506 1
20003093 200507 1
20003093 200510 1
20003093 200704 1
20002994 200001 1
20002994 200111 1
20002994 200112 1
20002994 200201 1
20002994 200202 1
20002994 200203 1
----------------------------
现在我想根据hh 取最大的dfny 的一条记录 ,比如上面的查询结果就是
20003093 200704 1
20002994 200203 1
--------------------------------------------
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;
速度也好不到哪里去,哪个高人指导一下
-----------------------
hh dfny sfpc
20003093 200505 1
20003093 200506 1
20003093 200507 1
20003093 200510 1
20003093 200704 1
20002994 200001 1
20002994 200111 1
20002994 200112 1
20002994 200201 1
20002994 200202 1
20002994 200203 1
----------------------------
现在我想根据hh 取最大的dfny 的一条记录 ,比如上面的查询结果就是
20003093 200704 1
20002994 200203 1
--------------------------------------------
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;
速度也好不到哪里去,哪个高人指导一下
-----------------------
解决方案 »
- SQL查询当前审核人的问题~求赐教
- 请问要在linux调用oci的oopen等函数,应该连接哪个库?谢谢
- 求教:视图存在重复记录、查询卡死等问题
- 求助:怎样用oracle的pl/sql软件将数据库中所有的建表语句以及数据导出
- 存储过程调用 java时,日期参数如何传递????多谢
- 异构表之间数据互导问题
- 求助:遇到两个面试题如下(急急急急!!!!!!!!!!!!!!!!!!!!!!!!!!)
- 关于数据库表字段由用户来制定的解决方法
- 为什么这条语句这么慢?
- 如何判断时间是否有错误?
- 字符集不同造成的乱码怎么解决?
- 比如说一个员工表,有EMPNO,DEPTID,SALARY,怎么找出每个部门工资前3的员工
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