Skip to content

Instantly share code, notes, and snippets.

@OneWeb
Created June 11, 2024 15:40
Show Gist options
  • Save OneWeb/e123a8ad32ef8a07bb297a296fd9cab3 to your computer and use it in GitHub Desktop.
Save OneWeb/e123a8ad32ef8a07bb297a296fd9cab3 to your computer and use it in GitHub Desktop.
Collector Points Balance SQL
SELECT
(SELECT COALESCE(SUM(r.points_value), 0) FROM gc_promo_receipt r
WHERE r.user_id = 1
AND r.status = 'Approved')
-
(SELECT COALESCE(SUM(l.reward_type_points_cost), 0) FROM gc_promo_user_reward_claim_ledger l
INNER JOIN gc_promo_user_reward_claim c ON c.id = l.user_reward_claim_id
WHERE c.redeemed_by_user_id = 1)
AS points_balance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment