Column aliases and computations are performed in the projection (SELECT
) phase of the query, which occurs after the selection (WHERE
and JOIN
) phase. Because of this, they can't be referenced in the WHERE
clause or in a JOIN
condition because they do not yet exist. You can either use your query with the SELECT
clause as a subquery or you can duplicate the computation in the WHERE
clause:
select *
from
(select [FirstName], difference([FirstName], 'mitch') as similarity
from [Dev].[dbo].[Name]) src
where similarity > 2
order by similarity desc
or
select [FirstName], difference([FirstName], 'mitch') as similarity
from [Dev].[dbo].[Name]
where difference([FirstName], 'mitch') > 2
order by similarity desc
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…