Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Select
- A.date,
- A.mid,
- B.carname,
- B.regionname,
- B.amount,
- Sum(A.TotalMFTs)
- from
- (select
- Date(c.created_at + interval '8' hour) as date,
- m.id as mid,
- count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
- from charges c
- join members m
- on m.id = c.member_id
- left join reservations r
- on r.id = c.reservation_id
- where c.created_at + interval '8' hour >= '2019-3-1 00:00'
- and m.imaginary = 'normal'
- and c.kind = 'subscriptionFee'
- #and r.state = 'completed'
- Group by Date,mid) A
- left join
- (select
- distinct m.id as mid,
- min(Date(r.start_at + interval '8' hour)) as date,
- c.id as carid,
- cc.car_name as carname,
- z.id as zoneid,
- z.region as regionname,
- (p.amount) as amount
- from reservations r
- left join members m
- on m.id = r.member_id
- left join cars c
- on c.id = r.car_id
- left join car_classes cc
- on cc.id = c.car_class_id
- left join zones z
- on z.id = c.zone_id
- join payments p
- on p.reservation_id = r.id
- where r.start_at + interval '8' hour >= '2019-3-1 00:00'
- and r.state = 'completed'
- group by mid) B
- on A.mid = B.mid
- group by A.Date,B.carname,B.regionname
Advertisement
Add Comment
Please, Sign In to add comment