Reputation: 1522
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'
Upvotes: 0
Views: 958
Reputation: 16
i think you just miss spelled p_discont, maybe you should try with p_discount
SELECT *, (product_price - product_sell_price) / product_sell_price*100 as p_discount
FROM `products`
WHERE product_price IS NOT NULL
AND p_discount > 25
ORDER BY p_discount DESC
Upvotes: 0
Reputation: 32003
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
Upvotes: 1