日期:2014-05-17  浏览次数:20934 次

oracle 查询两段数据Union不了。。出现什么未正确结束 求高手指导。。。
本帖最后由 CaoYYYY 于 2013-06-06 08:56:11 编辑
select t.bh1 
,t.name1
,t.content
,t.deductDescn
,a.score as cbsscore
,b.score as jlscore
,c.score as yzscore
from
(Select cgat.id as itemId 
,Case When cgat.code='GCZZ' Then '一'
 Else
     Case When cgat.code='GCZL' Then '二'
     Else
         Case When  cgat.code='GCJD' Then '三'
         Else 
              Case When cgat.code='AQWM' Then '四'
              Else
                  cgat.code
              End
         End 
     End
 End bh1
,Name || '(' || cgat.score || ')' As name1
,Name || '(' || cgat.score || ')' As content
,Name || '(' || cgat.score || ')' As Deductdescn
,Name || '(' || cgat.score || ')' As name4
,Name || '(' || cgat.score || ')' As contentCode
,Name || '(' || cgat.score || ')' As name6
,treecode 
From ip_ct_goodJob_assessType  cgat
Where
 length(treeCode)=5
and name<>'加分因素'
 And contractType='XMHT_SG_HT'
 
 union
 
 
 select cgai.id as itemId
 ,cgat1.code as bh2
 ,cgat1.name || '(' || cgat1.score || ')' as name2
 ,cgai.content as content
 ,cgai.Deductdescn as Deductdescn
,cgai.contentCode
,'' name3
,''name4
,cgat1.treecode || '000' ||cgai.contentCode as treecode
 from ip_ct_goodJob_assessItem cgai
 ,ip_ct_goodJob_assessType cgat1
 ,ip_ct_goodJob_assessType cgat2
 where 
     cgai.assessTypeId=cgat1.id
and cgai.activity = 1
and cgat2.activity =1 
and cgat1.contracttype='XMHT_SG_HT'
and cgat2.contracttype='XMHT_SG_HT'
and cgat1.parentid=cgat2.id
and cgat1.name<>'加分因素'
) t
left join 
(
 select cgjd.itemid
 ,cgjd.score
  from ip_ct_goodJob cgj
 ,ip_ct_goodJob_detail cgjd
 where 
 cgj.id=cgjd.goodjobid
 and cgj.postid='contractor'
 and cgj.id=''
 and cgj.contractid=''
) a
on t.itemId=a.itemid
left join 
(
 select cgjd.itemid
 ,cgjd.score
  from ip_ct_goodJob cgj
 ,ip_ct_goodJob_detail cgjd
 where 
 cgj.id=cgjd.goodjobid
 and cgj.postid='supervisor'
 and cgj.id=''
 and cgj.contractid=''
) b
on t.itemId=b.itemid