Interview Query

Attribution Rules

1
Have you seen this question before?

Write a query that creates an attribution rule for each user. If the user visited Facebook or Google at least once then the attribution is labeled as “paid.” Otherwise, the attribution is labeled as “organic.”

Example:

Input:

user_sessions table

Column Type
created_at DATETIME
session_id INTEGER
user_id INTEGER

attribution table 

Column Type
session_id INTEGER
channel VARCHAR

Output:

Column Type
user_id INTEGER
attribute VARCHAR
Next question: Bootstrapping Samples
.....
MySQL 8.0.17
Loading editor
Use Shift + Enter to run query