在隨後創建視圖,我得到一個錯誤來自視野錯誤條款
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
其實我需要做四個結合表格以在單個表格中獲取所有需要的記錄。請幫忙
發佈錯誤訊息 –
#1349 - 視圖的SELECT包含FROM子句中的子查詢 –
創建視圖無法從中找到子查詢。看看這個解決方法:http://stackoverflow.com/questions/8428641/views-select-contains-a-subquery-in-the-from-clause –