2016-09-09 3 views
0

where文でエイリアスを使用することはできません。しかし、私はどのようにこのクエリを書き直すことができますか?カラムリファレンス 'name'があいまいです

 SELECT 
     CASE 
     WHEN app_reports_mgmt.reports.rid = app_reports_mgmt.report_template.rid THEN 
     app_reports_mgmt.report_template.name 
     ELSE app_reports_mgmt.reports.name 
     END AS name 
FROM app_reports_mgmt.reports left join app_reports_mgmt.report_template on app_reports_mgmt.reports.rid = app_reports_mgmt.report_template.rid 
where LOWER(name) LIKE LOWER('%daily%') and app_reports_mgmt.reports.report_status = 'Active' order by name 

答えて

1

は、いくつかの調査の後、問題がwhere句、ないorder byです。

あなたは位置によって参照することによってこの問題を解決することができます:

select (case when r.rid = t.rid 
      then t.name 
      else r.name 
     end) as name 
from app_reports_mgmt.reports r left join 
    app_reports_mgmt.report_template t 
    on r.rid = t.rid 
where (case when r.rid = t.rid then lower(t.name) else lower(r.name) end) like lower('%daily%') and 
     r.report_status = 'Active' 
order by name; 
+0

おかげでたくさんの仲間を! – Odinovsky