Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @start := '2018-12-31 00:00';
- 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
- (select
- month(p.created_at + interval 8 hour) as month,
- sum(p.point) as redeem
- from points p
- where p.state = 'normal'
- and date(p.created_at + interval 8 hour) >= @start
- and p.type = 'redeem'
- group by 1) A
- left join
- (select
- month(p.created_at + interval 8 hour) as month,
- sum(p.point) as earn
- from points p
- where p.state = 'normal'
- and date(p.created_at + interval 8 hour) >= @start
- and p.type = 'earn'
- group by 1) B
- on A.month = B.month
Add Comment
Please, Sign In to add comment