-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9632_Host_Popularity_Rental_Prices.sql
59 lines (49 loc) · 1.67 KB
/
9632_Host_Popularity_Rental_Prices.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
https://platform.stratascratch.com/coding/9632-host-popularity-rental-prices?
Host Popularity Rental Prices
You’re given a table of rental property searches by users. The table consists of search results and outputs host information for searchers. Find the minimum, average, maximum rental prices for each host’s popularity rating. The host’s popularity rating is defined as below:
0 reviews: New
1 to 5 reviews: Rising
6 to 15 reviews: Trending Up
16 to 40 reviews: Popular
more than 40 reviews: Hot
Tip: The `id` column in the table refers to the search ID. You'll need to create your own host_id by concating price, room_type, host_since, zipcode, and number_of_reviews.
Output host popularity rating and their minimum, average and maximum rental prices.
Table: airbnb_host_searches
airbnb_host_searches
id int
price float
property_type varchar
room_type varchar
amenities varchar
accommodates int
bathrooms int
bed_type varchar
cancellation_policy varchar
cleaning_fee bool
city varchar
host_identity_verified varchar
host_response_rate varchar
host_since datetime
neighbourhood varchar
number_of_reviews int
review_scores_rating float
zipcode int
bedrooms int
beds int
*/
WITH A AS(
SELECT DISTINCT CONCAT(price,room_type,zipcode) AS host_id, price, number_of_reviews,
CASE
WHEN number_of_reviews = 0 THEN 'New'
WHEN number_of_reviews BETWEEN 1 AND 5 THEN 'Rising'
WHEN number_of_reviews BETWEEN 6 AND 15 THEN 'Trending Up'
WHEN number_of_reviews BETWEEN 16 AND 40 THEN 'Popular'
WHEN number_of_reviews > 40 THEN 'Hot'
END
AS popularity
FROM airbnb_host_searches)
SELECT popularity, MIN(price) AS minimum, AVG(price) AS average, MAX(price) AS maximum
FROM A
GROUP BY 1
;