ahmedrahil786

WIP - Oneway Trips - MFTs - weekly - For Jason

Jul 9th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Select Weekofyear(A.date) as week, Count(A.rid) as oneway_MFT from
  2. (select FB.rid2 as rid, FB.mid as mid, FB.way as way, FB.date as date from
  3. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  4. date(r.start_at + interval '8' hour) as date,
  5. fbo.mid as mid,fbo.rid,fbo.way as way from
  6. reservations r
  7. join
  8. (select
  9. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  10. (select
  11. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  12. from reservations r join members m on m.id = r.member_id
  13. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  14. where fbi.way in ('oneway','onewayReturn') ) fbo on fbo.rid = r.id
  15. where r.start_zone_id in ('244','245') or r.end_zone_id in ('244','245') )FB
  16. where date(FB.date + interval '8' hour) >= '2019-01-01') A group by week order by week desc
Advertisement
Add Comment
Please, Sign In to add comment