UNION
this is the クエリを使用して、列の下部にある最後の 3 つの列の合計を表示したいという問題があります。
select a.app_file_id, a.app_fname,a.app_lname, l.tertiary_interest,l.loan_life,l.commit_date,
max(case when date(r.receipt_date)<='2012-4-01' and r.receipt_date = (select max(r.receipt_date) from receipt_history r where date(r.receipt_date)<='2012-4-01' ) then amount_owed else 0 end),
sum(case when r.receipt_on='Principal' and r.receipt_date >= STR_TO_DATE(CONCAT(2012, '-04-01'),'%Y-%m-%d') and r.receipt_date <= STR_TO_DATE(CONCAT(2012, '-03-31'), '%Y-%m-%d') + interval 1 year then r.receipt_amount end),
max(case when r.receipt_date<=STR_TO_DATE(concat(2013,'-4-01'),'%Y-%m-%d') and r.receipt_date = (select max(r.receipt_date) from receipt_history r where r.receipt_date<=STR_TO_DATE(concat(2013,'-4-01'),'%Y-%m-%d')) then amount_owed else 0 end)
from applicant a
left join loan l on l.l_app_file_id=a.app_file_id
left join receipt_history r on r.r_app_file_id=a.app_file_id
group by l.loan_id
union
select '', '','','','','',sum(max_pay_april_G),sum(fiscal_Prin_G),sum(final_bal )
from(
a.app_file_id, a.app_fname,a.app_lname, l.tertiary_interest,l.loan_life,l.commit_date,
max(case when date(r.receipt_date)<='2012-4-01' and r.receipt_date = (select max(r.receipt_date) from receipt_history r where date(r.receipt_date)<='2012-4-01' ) then amount_owed else 0 end) as max_pay_april_G,
sum(case when r.receipt_on='Principal' and r.receipt_date >= STR_TO_DATE(CONCAT(2012, '-04-01'),'%Y-%m-%d') and r.receipt_date <= STR_TO_DATE(CONCAT(2012, '-03-31'), '%Y-%m-%d') + interval 1 year then r.receipt_amount end) as fiscal_Prin_G,
max(case when r.receipt_date<=STR_TO_DATE(concat(2013,'-4-01'),'%Y-%m-%d') and r.receipt_date = (select max(r.receipt_date) from receipt_history r where r.receipt_date<=STR_TO_DATE(concat(2013,'-4-01'),'%Y-%m-%d')) then amount_owed else 0 end) as final_bal
from applicant a
left join loan l on l.l_app_file_id=a.app_file_id
left join receipt_history r on r.r_app_file_id=a.app_file_id
group by l.loan_id
)q;
私は3つのテーブルを使用していて、列名が問題を引き起こす可能性があるため、混乱しているように見えるかもしれませんが、誰かがクエリの分析を手伝ってくれて、どこが間違っていたのかを知ることができれば、本当に助けていただければ幸いです。表示されるエラー メッセージは 13 行目に誘導されます。質問を明確にして、支援を得ることができれば幸いです。どうもありがとうございます