Guest User

Untitled

a guest
Nov 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. CREATE VIEW rep_ops_first_property_offer as (
  2. SELECT
  3. ap.id "ap_id",
  4. ap.name,
  5. CONCAT(ag.first_name," ",ag.last_name) "account_manager",
  6. IF(ap.`account_management_key_account` = 1,1,0) "ap_type",
  7. p.id,
  8. ao.id "offer_id",
  9. ifnull(ap.first_offer_published_at, min(ao.published_at)) "published_date",
  10. ao.created_source,
  11. ao.created_by_type,
  12. IF(pp.created_by = 'c4f8a449-e69e-484a-a277-939b0a1a1e63',1,0) "old_ss",
  13. count(distinct ao.id) "total_offers",
  14. p.address_city_code "city",
  15. ao.available_from "availability",
  16. bs.score
  17.  
  18.  
  19. FROM prod_reporting.accommodation_offer ao
  20. LEFT JOIN prod_reporting.property AS p ON p.id = ao.property_id
  21. LEFT JOIN prod_reporting.accommodation_provider AS ap ON ap.id = p.accommodation_provider_id
  22. LEFT JOIN prod_reporting.prospective_property pp ON p.id = pp.id
  23. LEFT JOIN prod_reporting_ops.rep_ops_ac_bookable_supply AS bs ON bs.offer_id = ao.id
  24. LEFT JOIN prod_reporting.agency_staff as ag ON ag.id = ap.account_manager
  25.  
  26. WHERE ap.is_test = 0
  27. AND ao.published_at is not null
  28. GROUP BY p.id
  29. ORDER BY 5,1);
Add Comment
Please, Sign In to add comment