Guest User

Untitled

a guest
Dec 10th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. create view rep_fin_existing_supply_available_om as (
  2. SELECT
  3. ao.id AS id,
  4. left(ifnull(fc.focus_city_name_2,'Others'),2) AS market,
  5. ifnull(fc.focus_city_name_2,'Others') AS city,
  6. year(ao.published_at) AS year,
  7. uw.week_up AS week,
  8. ao.id AS offer_id,
  9. ao.offer_type AS offer_type,
  10. p.typology_number_of_bedrooms AS total_bedrooms,
  11. ao.number_of_units AS total_nits,
  12. nn.name AS ops_neighborhood,
  13. (ao.reference_rent_amount / 100) AS rent,
  14. (case when (ap.account_management_key_account = '1') then 'KA' else 'SML' end) AS ap_type,
  15. (case when ((ao.created_by_type = 'accommodation-provider') or (ao.created_by = 'c4f8a449-e69e-484a-a277-939b0a1a1e63')) then 'self-service' else 'agents' end) AS created_by,
  16. (case when (ao.created_by = ap.id) then 'non full edit' else 'full edit' end) AS ss,
  17. cast(ao.available_from as date) AS availability,if((ao.available_from <= (curdate() + interval 30 day)),'1','0') AS available_30d,
  18. if((ao.available_from <= (curdate() + interval 90 day)),'1','0') AS available_90d,cast(ao.availability_last_update_at as date) AS last_availability_update,if((ao.availability_last_update_at >= (curdate() + interval -(30) day)),'1','0') AS updated_30d,
  19. ifnull(bs.score,0) as 'bookable_score'
  20.  
  21. FROM
  22. prod_reporting.accommodation_offer ao
  23. left join prod_reporting.property p on p.id = ao.property_id
  24. left join prod_reporting.accommodation_provider ap on ap.id = p.accommodation_provider_id
  25. left join prod_reporting_ops.focus_city_other_markets fc on fc.city = p.address_city_code
  26. left join prod_reporting.prospective_property pp on p.id = pp.id
  27. left join prod_reporting.neighborhood nn on nn.id = p.neighborhood_id
  28. left join prod_reporting_ops.uniplaces_week uw on uw.date_week = date(ao.published_at)
  29. left join prod_reporting_ops.rep_ops_ac_bookable_supply bs on bs.offer_id = ao.id
  30. where ap.is_test = 0
  31. and isnull(ao.parent_id)
  32. and ao.published_at is not null
  33. and p.out_of_platform = 0
  34. and ap.out_of_platform = 0 and ao.published = 1
  35. and fc.flag = 2);
Add Comment
Please, Sign In to add comment