全外连接的语法是两个表之间作的,你搞三个表,语法就错了 在tab_2 full outer join tab_3时 on tab_1.Tax_Type = tab_2.Tax_Type 当然会报错了
如果实现功能如下: TAX_TYPE SUM1 SUM2 SUM3:=========================================================== SELECT A.TAX_TYPE,SUM1,SUM2,SUM3 FROM (select Tax_Type,NVL(sum(Tax_number),0) sum1 from table1 where substr(to_char(Tax_Time),1,6)=substr(to_char sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Tax_Type) tab_1, (select Tax_Type,NVL(sum(Tax_number),0) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Tax_Type) tab_2, (select Tax_Type,NVL(sum(Tax_Number),0) sum3 from table1 where Company_Name like '%北京%' group by Tax_Type) tab_3 WHERE TAB_1.TAX_TYPE(+)=TAB_2.TAX_TYPE(+) AND TAB_1.TAX_TYPE(+)=TAB_3.TAX_TYPE(+)
如楼上所说,全外连接的语法是两个表之间作的,你搞三个表,语法就错了这样就可以了! select d.*,tab3.sum3 from (select sum1 ,sum2 tax_type from (select Tax_Type,sum(Tax_number) sum1 from table1 where substr(to_char(Tax_Time),1,6)=substr(to_char sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Tax_Type) tab_1 full outer join (select Tax_Type,sum(Tax_number) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Tax_Type) tab_2 on tab_1.Tax_Type = tab_2.Tax_Type ) d full outer join (select Tax_Type,sum(Tax_Number) sum3 from table1 where Company_Name like '%北京%' group by Tax_Type) tab_3 on d.Tax_Type = tab_3.Tax_Type;
在tab_2 full outer join tab_3时 on tab_1.Tax_Type = tab_2.Tax_Type 当然会报错了
TAX_TYPE SUM1 SUM2 SUM3:===========================================================
SELECT A.TAX_TYPE,SUM1,SUM2,SUM3
FROM
(select Tax_Type,NVL(sum(Tax_number),0) sum1 from table1
where substr(to_char(Tax_Time),1,6)=substr(to_char sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Tax_Type) tab_1,
(select Tax_Type,NVL(sum(Tax_number),0) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Tax_Type) tab_2,
(select Tax_Type,NVL(sum(Tax_Number),0) sum3 from table1 where Company_Name like '%北京%' group by Tax_Type) tab_3
WHERE TAB_1.TAX_TYPE(+)=TAB_2.TAX_TYPE(+)
AND TAB_1.TAX_TYPE(+)=TAB_3.TAX_TYPE(+)
select d.*,tab3.sum3 from
(select sum1 ,sum2 tax_type
from (select Tax_Type,sum(Tax_number) sum1 from table1
where substr(to_char(Tax_Time),1,6)=substr(to_char sysdate,'YYYYMMDD'),1,6) and Company_Name like '%北京%' group by Tax_Type) tab_1
full outer join (select Tax_Type,sum(Tax_number) sum2 from table1 where substr(to_char(Tax_Time),1,4)=substr(to_char(sysdate,'YYYYMMDD'),1,4) and Company_Name like '%北京%' group by Tax_Type) tab_2 on tab_1.Tax_Type = tab_2.Tax_Type ) d
full outer join (select Tax_Type,sum(Tax_Number) sum3 from table1 where Company_Name like '%北京%' group by Tax_Type) tab_3
on d.Tax_Type = tab_3.Tax_Type;
右连接:TAB_1.TAX_TYPE(+)=TAB_2.TAX_TYPE
zlqs(啊啊啊) ( )
你这种方法没有通用性,那假如说有4个表格,5个表格呢?那不是要嵌套很多啊?有没有更加方便的方法.