Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- E.*,
- F.MFT
- from
- (select
- c.coupon_policy_id as cpid,
- c.comment as couponname,
- count(c.activated_at) as TotalApplied,
- count(c.used_at) as totalredeems
- from coupons c
- where c.coupon_policy_id in (656,655)
- and c.state = 'normal'
- group by 1
- order by 1 asc) E
- left join
- (select
- B.cpid as cpid,
- count(A.mid) as MFT
- from
- (select
- ch.member_id as mid
- from charges ch
- where ch.created_at + interval '8' hour >= '2019-5-1 00:00'
- and ch.kind = 'subscriptionFee') A
- join
- (select
- distinct c.member_id as mid,
- c.coupon_policy_id as cpid,
- c.comment
- from coupons c
- where c.coupon_policy_id in (656,655)
- and c.used_at is not null
- group by 1,2
- order by 1 asc) B
- on B.mid = A.mid
- group by B.cpid) F
- on E.cpid = F.cpid
Advertisement
Add Comment
Please, Sign In to add comment