Home > OS >  How do I use a WHERE on a calculated column
How do I use a WHERE on a calculated column

Time:01-20

I have a calculated column in my sql query and I want to use it in my where clause, normally I use the table names and then what I want to filter. In this case I don't have that option

this is in my SELECT statement, Its a basic margin calculation SELL-COST/SELL*100 to give me the margin.

CONVERT(DECIMAL(10,2),(T_CUSTOMERPRICELISTBASESTANDARDRULE_PRICEDEFINITION.C_NETPRICE - T_PRODUCT_PURCHASING.C_LISTPRICEACTUAL)/T_CUSTOMERPRICELISTBASESTANDARDRULE_PRICEDEFINITION.C_NETPRICE ) * 100 Percentage

what I would like to do is use the WHERE clause to filter the above statement anything below 15

CodePudding user response:

You need to use a table expression to name that column officially. Then the outer query can use it as needed. For example:

select *
from (
  select a, b, a   b as c from t
) x
where c > 10 -- "c" exists in the outer query
  •  Tags:  
  • sql
  • Related