flâneur — a map of the web's best reading

Average Post Hiatus | Facebook SQL Interview Question

datalemur.com · 331 words · saved by 1 readers

Given a table of Facebook posts, for each user who posted at least twice in 2021, write a query to find the number of days between each user’s first post of the year and last post of the year in the year 2021. Output the user and number of the days between each user's first and last post. p.s. If you've read the Ace the Data Science Interview and liked it, consider writing us a review? The dataset you are querying against may have different input & output - this is just an example! First, we can use the MIN() and MAX() aggregate functions on the post_date column to retrieve the earliest and latest post dates, and substract one from another accordingly. To calculate the difference for each user, we GROUP the results by user_id, and then filter for posts made in the year 2021. To do so, we use the DATE_PART() function to extract the year from the post_date column. In the final step, to exclude users who have posted only once during the year, we apply the HAVING clause with a COUNT() cond

Average Post Hiatus | Facebook SQL Interview Question Share Premium Back to questions Average Post Hiatus (Part 1) Facebook SQL Interview Question Average Post Hiatus (Part 1) Facebook SQL Interview Question Question Solution Discussion Submissions Given a table of Facebook posts, for each user who posted at least twice in 2021, write a query to find the number of days between each user’s first post of the year and last post of the year in the year 2021. Output the user and number of the days between each user's first and last post. p.s. If you've read the Ace the Data Science Interview and li

Explore this link on the map →

saved by

related reading