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

求上面SQL优化,表的连接太多了

2012-12-30 
求下面SQL优化,表的连接太多了。 select a.id,a.claimno ,a.username ,a.appealreason ,a.appealstatus,a.a

求下面SQL优化,表的连接太多了。

 


select a.id,
            a.claimno ,
            a.username ,
            a.appealreason ,            
            a.appealstatus,
            a.appealResult,
            b.tasksuggestion ,
            b.updater ,
            (select tasksuggestion from claimTasks  where tasktype='ZJPD' and taskid=a.claimno) ptasksuggestion
            from 
            appealInfo a ,
            claimTasks b
            where  
            b.tasktype='SSPD' and  a.claimno=b.taskid and 
            appealFlag='1' and 1=1  
            order by id desc

目前执行时间太长了3.563s  2000多条数据
[解决办法]
你这一行莫名其妙啊
(select tasksuggestion from claimTasks  where tasktype='ZJPD' and taskid=a.claimno) ptasksuggestion

你到底想要什么功能啊
[解决办法]
SELECT A.ID,
       A.CLAIMNO,
       A.USERNAME,
       A.APPEALREASON,
       A.APPEALSTATUS,
       A.APPEALRESULT,
       B.TASKSUGGESTION,
       B.UPDATER,
       --   (select tasksuggestion from claimTasks  where tasktype='ZJPD' and taskid=a.claimno) ptasksuggestion 
       --以上相对占用资源,可改成decode的写法
       DECODE(B.TASKTYPE, 'ZJPD', B.TASKSUGGESTION)
  FROM APPEALINFO A, CLAIMTASKS B
 WHERE B.TASKTYPE = 'SSPD'
   AND A.CLAIMNO = B.TASKID
   AND APPEALFLAG = '1'
   AND 1 = 1
 ORDER BY ID DESC

热点排行