Results 1 to 2 of 2
Jan 17, 2011, 06:24 #1
- Join Date
- Jan 2011
- 0 Post(s)
- 0 Thread(s)
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.
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'];
SUM(credits)-SUM(debits) as loyalty_points