select
t_a.a,t_a.b,max(t_a.c) c,
MAX (t_a.d)KEEP (DENSE_RANK FIRST
ORDER BY t_a.c _ DESC) d_
from t_a
group by
t_a.a,t_a.b
---------------------------------------------------------------------------------------------------------------------
单表
select max(t2.main_id) KEEP(DENSE_RANK FIRST ORDER BY t2.creatime DESC)
from
T_FILE_001_DOCUMENT_GENERATE t1,T_common_001_MAIN t2
where t1.APPLY_CODE=t2.main_id and t1.approval_num='吉长辖演许字【2013】第001号'
------------------------------------
-- Created on 2013-10-25 by 删 除公司名称重复的数据
declare
-- Local variables here
l_rowid rowid;
begin
-- Test statements here
for cur_v in(
select comp_name from T_Service_017_Mainbasicinfo group by comp_name having count(*)>1
) loop
select MAX (rowid) KEEP (DENSE_RANK FIRST
ORDER BY T.Sys_Receive_Date DESC) into l_rowid from T_Service_017_Mainbasicinfo t where t.comp_name =cur_v.comp_name ;
delete from T_Service_017_Mainbasicinfo t where comp_name =cur_v.comp_name and rowid<> l_rowid ;
end loop;
end;
本文介绍了使用SQL进行复杂查询的方法,包括利用MAX函数结合DENSE_RANKFIRST进行最大值选择及保持最新记录的选择技巧,并展示了如何通过PL/SQL块删除公司名称重复的数据记录。

被折叠的 条评论
为什么被折叠?



