Advertisement
Guest User

Untitled

a guest
May 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT * FROM(SELECT airbnbdata.*,
  2.        zmrp.price AS zillow_monthly_price, zmrp.city, CAST((zmrp.price/airbnbdata.median_per_day) as numeric(10,2)) as revenue_crossover_point
  3. FROM   (SELECT a.zipcode,
  4.                a.DATE,
  5.                a.bedrooms,
  6.                PERCENTILE_CONT(0.5)
  7.                  within GROUP ( ORDER BY a.price ) AS median_per_day
  8.         FROM   (SELECT filted_listing.neighbourhood_cleansed AS zipcode,
  9.                        Date_trunc('month', calendar.DATE)    AS DATE,
  10.                        filted_listing.bedrooms,
  11.                        CASE
  12.                          WHEN calendar.price IS NULL THEN filted_listing.price
  13.                          ELSE calendar.price
  14.                        END
  15.                 FROM   (SELECT *
  16.                         FROM   listing
  17.                         WHERE  room_type = 'Entire home/apt'
  18.                                AND bedrooms > 0
  19.                                AND bedrooms IS NOT NULL
  20.                                AND last_scraped IS NOT NULL
  21.                                AND neighbourhood_cleansed IS NOT NULL) AS
  22.                        filted_listing,
  23.                        calendar
  24.                 WHERE  filted_listing.id = calendar.listing_id) AS a
  25.         GROUP  BY zipcode,
  26.                   DATE,
  27.                   bedrooms) AS airbnbData,
  28.        zillow_median_rental_price AS zmrp
  29. WHERE  airbnbData.zipcode = zmrp.zipcode
  30.        AND airbnbData.DATE = zmrp.DATE
  31.        AND airbnbData.bedrooms = zmrp.bedrooms) as final_table
  32. WHERE upper(city) = 'BOSTON'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement