-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfromMicrosoft2Google.sql
More file actions
27 lines (24 loc) · 867 Bytes
/
fromMicrosoft2Google.sql
File metadata and controls
27 lines (24 loc) · 867 Bytes
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
/*
From Microsoft to Google, Hard SQL StrataScratch:
Consider all LinkedIn users who, at some point, worked at Microsoft.
For how many of them was Google their next employer right after Microsoft (no employers in between)?
--------------------------
This problem is practical when analyzing employee or customer churn.
What graduates were most successul from 'x' school? Or former companies?
*/
--- SQL Server Solution self join method:
WITH RankedEmployment AS (
SELECT
user_id,
employer,
start_date,
end_date,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY start_date) AS employment_rank
FROM linkedin_users
)
SELECT COUNT(*) AS count_of_users
FROM RankedEmployment AS a
JOIN RankedEmployment AS b ON a.user_id = b.user_id
WHERE a.employer = 'Microsoft'
AND b.employer = 'Google'
AND b.employment_rank - a.employment_rank = 1;