Member-only story

Tweets’ Rolling Averages — SQL Question Asked By Twitter

Solving SQL Question Asked By Twitter

Suraj Mishra
3 min readOct 26, 2022

Originally Published in https://asyncq.com/

Photo by Caspar Camille Rubin on Unsplash

Introduction

  • In this article we will solve Tweets’ Rolling Averages SQL question which is asked by Twitter as per DataLemur website.

If you don’t know DatLemur then please do visit , it’s one of the best website to practice SQL questions and improve your SQL skills.

Question

  • We have been given tweets that were made over given period of time.
  • We need to calculate 3-day rolling average of tweets published by each user for each date that a tweet was posted.
  • As we can see in our output for user_id, 2 tweets were made so avg is 2, then on next day 1 tweet was made, so total 3 tweets made in 2 days hence avg is 3/2 = 1.5, then on third day 1 more tweet made so total 4 tweets in 3 days makes it 1.33 as avg.

--

--

Suraj Mishra
Suraj Mishra

Written by Suraj Mishra

Staff Software Engineer @PayPal ( All opinions are my own and not of my employer )

No responses yet