I want to calculate discount in SQL query and want to get products having discount greater than 25. I am trying with following query. Please correct me what i am doing wrong. Thank you
SELECT *, (product_price - product_sell_price) / product_sell_price*100 as p_discount FROM `products` WHERE product_price IS NOT NULL AND p_discont > 25 ORDER BY p_discount DESC
I am getting following error.
#1054 - Unknown column 'p_discont' in 'where clause'
Advertisement
Answer
use inline condition in where clause
SELECT *, (((product_price - product_sell_price) / product_sell_price)*100) as p_discount FROM `products` WHERE product_price IS NOT NULL AND (((product_price - product_sell_price) / product_sell_price)*100) > 25 ORDER BY p_discount DESC