Skip to content

Solving a LinkedIn Data Science SQL Interview Question

Bram Adams
Bram Adams
1 min read

Table of Contents

peepoThink (1)

  • we could use GROUP BY to see how many posting share the same uid
  • we could then SELECT WHERE count == 1
  • use DATE_TRUNC to group by year or
  • use WHERE to split each into 180 day intervals from now()

visualize the output and work backwards, make an output table, split into intermediate tables to process

WITH user_job AS (
	SELECT u_id, j_id, COUNT(DISTINCT date_posted) AS num_posted
	FROM jobs
	GROUP BY u_id, j_id
	SUM(CASE WHEN avg_posted > 1 THEN 1 END) AS posted_multiple
	, SUM(CASE WHEN avg_posted = 1 THEN 1 END) AS posted_once
		user_id, AVG(num_posted) AS avg_posted
	FROM user_job
	GROUP BY user_id
) AS t

HAVING won't work because it will filter values

Post Mortem

WITH - named function
COUNT(DISTINCT field_name) - get count of distinct values in field
GROUP_BY creates sub tables on different keys
END - end the if
ELSE - else
AVG() - get average of field

Use intermediate tables to get to the final table


Bram Adams

writer, programmer


Related Posts

Members Public

Notes on The History of Menswear

All about the history of menswear, from the Chinese ruling class wearing nail polish to the introduction of modern streetwear.

Notes on The History of Menswear
Members Public

Notes on OpenAI Q&A Finetuning GPT-3 Vs Semantic Search - Which to Use, When, and Why

A great video about finetuning vs semantic search. Finetuning teaches a model to write new patterns, not to have a theory of mind.

Members Public

I Programmed a YouTube Clipper

Just to capture this goated moment on a Kripp vid Are you on the guest list? x 3 It captures the current time from a YouTube share link and adds 5 seconds to the end time, subtracts 5 seconds from the start time. Get it here ⬇️ GitHub - bramses/ytclip-10s