Home > other >  ERROR: syntax error at or near "case" Position: 226
ERROR: syntax error at or near "case" Position: 226

Time:05-18

select 
       case when cld.last_milestone='APPROVED' THEN clf.application_received_and_approved_at
       case when cld.last_milestone='LOCK' THEN clf.locked_at
       case when cld.last_milestone='FUNDING' THEN clf.funded_at
       end as Last_Milestone_at
from
core.loan_file_milestone_days as clf

I CANNOT UNDERSTAND WHAT WENT WRONG HERE?

CodePudding user response:

Correct:

select 
   case
       when clf.last_milestone='APPROVED' THEN clf.application_received_and_approved_at
       when clf.last_milestone='LOCK' THEN clf.locked_at
       when clf.last_milestone='FUNDING' THEN clf.funded_at
   end as Last_Milestone_at
from
core.loan_file_milestone_days as clf

CodePudding user response:

select clf.loan_file_id,cld.last_milestone,
       case cld.last_milestone
       when 'APPROVED' THEN clf.application_received_and_approved_at
       when 'LOCK' THEN clf.locked_at
       when 'FUNDING' THEN clf.funded_at
       end as Last_Milestone_at
from
core.loan_files as clf
inner join
core.loan_file_milestone_days as cld
using(loan_file_id)

THIS IS THE SOLVED ONE THANK YOU GUYS

  • Related