Interview Query

Page Recommendations

Start Timer

0:00:00

Upvote
5
Downvote
Save question
Mark as completed
View comments (18)
Next question

You’re the data scientist for Facebook local businesses. Each local business has a page that can sponsor an ad in different local zip codes.

Write a query that for every page, gets the percentage of the users who ended up recommendeding the page and live in the same postal code as the page sponsorship.

Note: A page can sponsor multiple postal codes.

Example:

Input:

page_sponsorships table

Column Type
page_id INTEGER
postal_code VARCHAR
price FLOAT

recommendations table 

Column Type
user_id INTEGER
page_id INTEGER

users table

Column Type
id INTEGER
postal_code VARCHAR

Output:

Column Type
page INTEGER
postal_code VARCHAR
percentage FLOAT
.
.
.
.
.


Comments

Loading comments