getting the SUM of 2 fields and subtracting
Users on my site can aqquire points for certain actions. My table is:
member_id | points_count | points_type | points_for | date
points_count are the points that are credited/debited
points_type is either a credit (1) or debit (2).
I had originally just added and subtracted the points in my member table, but now id like to keep track of what the points were credited for.
Would someone be able to show me the correct statement to achieve this? And if posible do something like
SUM(credits.points_count) as points_credits,
SUM(debits.points_count) as points_debits
FROM loyalty_balance as credits
JOIN loyalty_balance as debits ON debits.member_id = '".$_SESSION['kt_login_id']."' AND debits.points_type = '2'
WHERE credits.points_type = '1' AND credits.member_id = ".$_SESSION['kt_login_id']."
$loyalty_points = $row['points_credits']-$row['points_debits'];
Thanks in advance for any help you can provide!
SUM(credits)-SUM(debits) as loyalty_points