sql - Difference between two columns in mysql -


I have two columns (credit and debit_mount) and I want to calculate the difference between them. Only need to get more records than zero or if the debited_amount field is taped, no matter that value is zero. Here is the sculveer I have tried. Please help

  SELECT `p_Id`,` user_id`, `doc_id`,` credit`, 'ap_data`,' end_on`, (credit-debit_man) as a credit` wp_loyalty_credits` From where `expired_on` & gt; Now ();    

You just in section:

 debit_mount or debit_mount is empty);  

Redefines your query credit in select . However, this is irrelevant, because you can not specify a column nickname in the where section, therefore, this column is credit which it is used if you add the table nickname So it is clear:

  select lc.p_Id, lc.user_id, lc.doc_id, lc.credit, lc.app_date, lc.expires_on, (lc.credit - lc.debited_amount ) As `wp_loyalty_credits` LC WHERE lc.expires_on> Now () and (lc.credit> lc.debited_amount or lc.debited_amount is zero);  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -