Home > Enterprise >  How to use placeholder in sql to another column in select
How to use placeholder in sql to another column in select

Time:03-01

i want to make a report and i already calculate it in one column then i want to use the result to another column, something like this

select addtime (timediff(a,b), c) as 'total_lead', case when
total_lead <= then 'yes' else 'no' end as 'check data'  from d

so i want to use the result and use it in another column anyone can help?

CodePudding user response:

You have to either repeat the expression:

select
    addtime(timediff(a,b), c) as 'total_lead',
    case when addtime(timediff(a,b), c) <= ? then 'yes' else 'no' end as 'check data'

or use a subquery, which may change the performance:

select
    total_lead,
    case when total_lead <= ? then 'yes' else 'no' end as 'check data'
from (
    select
        addtime(timediff(a,b), c) as 'total_lead'
    from d
) d_with_total_lead
  • Related