首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Informix >

百分求解informix下合并两个SQL语句,多谢~

2012-02-16 
百分求解informix下合并两个SQL语句,谢谢~~~~~~~~由于编写程序的要求需要在INFORMIX下将以下两条SQL合并为

百分求解informix下合并两个SQL语句,谢谢~~~~~~~~
由于编写程序的要求需要在INFORMIX下将以下两条SQL合并为一条SQL,求高手相助!!

select claim_folder_no,max(estimate_no) estimate_no from auto_estimated_l01 group by 1 into temp aaa with no log;

select sum(estimate_amount) amount from auto_estimated_l01 b,aaa a,auto_claim_folde01 f where b.claim_folder_no=f.claim_folder_no
 and a.claim_folder_no=b.claim_folder_no and a.estimate_no=b.estimate_no
 and (f.case_STATUS='0' or (f.case_STATUS in ('1','2','3') and date(f.CLOSING_DATE) >'11/30/2008')) and date(f.OPENING_DATE)<='11/30/2008';

[解决办法]
应该实现不了,informix不支持同一个sql对同一张表进行嵌套查询,楼主的两个sql中均包含auto_estimated_101表。楼主可以这样试一下,先执行sql1生成临时表aaa,然后执行sql2,如可正常执行,则如我红色部分所说。其实用一个太复杂的sql语句实现并不复杂的功能并不是最好的方法,完全可以通过两条清晰的sql实现此功能,我觉得这样步骤更清晰,思路也更清晰。
[解决办法]
如果是找出所有 claim_folder_no,最大estimate_no的SUM值。

SQL code
select sum(estimate_amount) amount from auto_estimated_l01 awhere not exists (select estimate_no from auto_estimated_l01 where claim_folder_no=a.claim_folder_no and estimate_no>a.estimate_no);
[解决办法]
你将
select claim_folder_no,max(estimate_no) estimate_no from auto_estimated_l01 group by 1
生成视图试试

热点排行