Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. create view aggregate_rooms_view as (
  2. select day,
  3. tenant_id,
  4. property_id,
  5. room_type,
  6. sum(on_the_market::int) as "total",
  7. sum(available::int) as "available",
  8. sum(on_the_market::int) - sum(available::int) as "unavailable",
  9. sum(off_the_market::int) as "off_the_market",
  10. sum(walk_in::int) as "walk_in",
  11. sum(out_of_order::int) as "out_of_order",
  12. sum(occupied::int) as "occupied",
  13. sum(occupied::int) * 100 / sum(on_the_market::int) as "percentage_occupied"
  14. from historic_rooms
  15. group by day, tenant_id, property_id, room_type
  16. );
  17.  
  18.  
  19. create view aggregate_transactions_view as (
  20. select day,
  21. tenant_id,
  22. property_id,
  23. transaction_type,
  24. room_revenue,
  25. category,
  26. sub_category,
  27. count(id) as "transactions",
  28. sum(amount) as "amount",
  29. sum(tax) as "tax",
  30. avg(amount) as "average_daily_rate"
  31. from raw_transactions
  32. group by day, tenant_id, property_id, transaction_type, room_revenue, category, sub_category
  33. );
  34.  
  35.  
  36.  
  37. create view aggregate_reservations_view as (
  38. select day,
  39. tenant_id,
  40. property_id,
  41. rate_plan,
  42. rate,
  43. room_type,
  44. sum(number_of_adults) as "adults",
  45. sum(number_of_children) as "children",
  46. sum(number_of_pets) as "pets",
  47. sum(total_guests) as "guests",
  48. sum(case loyalty_member_ids when '{}' then 0 else 1 end) as "members",
  49. sum(daily_account_revenue) as daly_account_revenue,
  50. sum(daily_account_tax) as daily_account_tax,
  51. sum(daily_account_revenue_and_tax) as daily_account_revenue_and_tax,
  52. sum(room_revenue) as room_revenue,
  53. sum(room_tax) as room_tax,
  54. sum(room_revenue_and_tax) as room_revenue_and_tax,
  55. sum(arrived_today::int) as arrival_rooms,
  56. sum(depart_today::int) as departure_rooms,
  57. sum(no_show::int) as no_show,
  58. sum(canceled::int) as cancelled,
  59. sum(late_checkout::int) as late_checkout,
  60. sum(early_arrival::int) as early_arrival,
  61. sum(case date_trunc('day', reservation_created_at) when day then 1 else 0 end) as "reservations_made_today",
  62. sum(case date_trunc('day', cancelation_at) when day then 1 else 0 end) as "cancelation_made_today"
  63.  
  64. from historic_reservations
  65. group by day, tenant_id, property_id, rate_plan, rate, room_type
  66. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement