2016-03-17 48 views
0

在隨後創建視圖,我得到一個錯誤來自視野錯誤條款

create or replace view viewfee as 
    select unique_id,session,course_cat,course,class,rollno, sum(adm_due) as adm_due, sum(tuition_due) as tuition_due, sum(exam_due) as exam_due from 
    (
    select unique_id,session,course_cat,course,class,rollno,null as adm_due, null as tuition_due, null as exam_due from tbstdinfo 
    union all 
    select unique_id,null,null,null,null,null,(adm_tot - sum(adm_payment)) AS adm_due, null, null from tbfeeadmission group by unique_id 
    union all 
    select unique_id,null,null,null,null,null,null, (tuition_tot - sum(tuition_payment)) AS tuition_due, null from tbfeetuition group by unique_id 
    union all 
    select unique_id,null,null,null,null,null,null, null, (exam_tot - sum(exam_payment)) AS exam_due from tbfeeexam group by unique_id 
    )x 
    group by unique_id 

,但如果我不視圖執行查詢,它工作正常

select unique_id,session,course_cat,course,class,rollno, sum(adm_due) as adm_due, sum(tuition_due) as tuition_due, sum(exam_due) as exam_due from 
(
select unique_id,session,course_cat,course,class,rollno,null as adm_due, null as tuition_due, null as exam_due from tbstdinfo 
union all 
select unique_id,null,null,null,null,null,(adm_tot - sum(adm_payment)) AS adm_due, null, null from tbfeeadmission group by unique_id 
union all 
select unique_id,null,null,null,null,null,null, (tuition_tot - sum(tuition_payment)) AS tuition_due, null from tbfeetuition group by unique_id 
union all 
select unique_id,null,null,null,null,null,null, null, (exam_tot - sum(exam_payment)) AS exam_due from tbfeeexam group by unique_id 
)x 
group by unique_id 

其實我需要做四個結合表格以在單個表格中獲取所有需要的記錄。請幫忙

+0

發佈錯誤訊息 –

+0

#1349 - 視圖的SELECT包含FROM子句中的子查詢 –

+0

創建視圖無法從中找到子查詢。看看這個解決方法:http://stackoverflow.com/questions/8428641/views-select-contains-a-subquery-in-the-from-clause –

回答

1

你不能在視圖定義子選擇,但是你可以做這樣的事情:

create or replace view intermediate_view as 
select unique_id,session,course_cat,course,class,rollno,null as adm_due, null as tuition_due, null as exam_due from tbstdinfo 
union all 
select unique_id,null,null,null,null,null,(adm_tot - sum(adm_payment)) AS adm_due, null, null from tbfeeadmission group by unique_id 
union all 
select unique_id,null,null,null,null,null,null, (tuition_tot - sum(tuition_payment)) AS tuition_due, null from tbfeetuition group by unique_id 
union all 
select unique_id,null,null,null,null,null,null, null, (exam_tot - sum(exam_payment)) AS exam_due from tbfeeexam group by unique_id 

然後

create or replace view viewfee as 
select unique_id,session,course_cat,course,class,rollno, sum(adm_due) as adm_due, sum(tuition_due) as tuition_due, sum(exam_due) as exam_due from intermediate_view 
group by unique_id 

爲一個workaro und

+0

我已經這樣做了,但我想在一個單一的觀點,無論如何謝謝 –