ahmedrahil786

Socar Points Redeemed Vs Earned - Rahil for Mr.Son

Oct 2nd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. set @start := '2018-12-31 00:00';
  2.  
  3. Select A.month, Round(B.earn,0) as points_earned , Round(A.redeem,0) as points_Redemmed, Round(B.earn - A.redeem,0) as total_Remaining from
  4.  
  5. (select
  6. month(p.created_at + interval 8 hour) as month,
  7. sum(p.point) as redeem
  8. from points p
  9. where p.state = 'normal'
  10. and date(p.created_at + interval 8 hour) >= @start
  11. and p.type = 'redeem'
  12. group by 1) A
  13. left join
  14. (select
  15. month(p.created_at + interval 8 hour) as month,
  16. sum(p.point) as earn
  17. from points p
  18. where p.state = 'normal'
  19. and date(p.created_at + interval 8 hour) >= @start
  20. and p.type = 'earn'
  21. group by 1) B
  22. on A.month = B.month
Add Comment
Please, Sign In to add comment