I have a query:
SELECT [outer].*,
(total_pain_patients / NULLIF ((SELECT Sum(total_pain_patients)
FROM [topplansperprovider]
WHERE [outer].[INDEX_IMSID] = [INDEX_IMSID]
AND plan_rank BETWEEN 1 AND 10), 0)) * 100 AS PercentOf,
pm.*,
percentof * pm.score
FROM [topplansperprovider] AS [outer]
left JOIN [payer Mapping] pm
on lower([outer].Plan_Name_OR_Payment_Type)=lower(pm.[ims payer name])
WHERE INDEX_IMSID = '1753841'
ORDER BY 6 ASC
My problem is with selecting this:
percentof * pm.score
Since percentof is the alias of a derived column, I don’t know how to use it in other columns.
- How do I select
percentof * pm.score? - If that is too difficult, how can I just add
percentofas a permanent column to my table?
You cannot use an alias like that, you will have to wrap the query in another select:
The column alias that you are calculating
percentofis not available for use in another column, unless is it used in a sub-query.