I have two columns (credit and debited_amount) and I want to calculate the difference between them.Only need to retrieve records greater than zero or if the debited_amount field is Null. Never mind if the value is zero.Here is the sqlquery which I have tried.Please help
SELECT `p_Id`,`user_id`,`doc_id`,`credit` ,`app_date`,`expires_on`,(credit -debited_amount) AS credit
FROM `wp_loyalty_credits` WHERE `expires_on`>now();
You just need to add the logic into the
where
clause:Your query redefines
credit
in theselect
. However, that is irrelevant, because you can't refer to a column alias in thewhere
clause. So, the columncredit
is what it used. It is clearer if you add table aliases: