Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL Live Coding With CTEs
00:00
5 left

SQL Live Coding With CTEs

MediumSQL · PostgreSQL

Problem

Write medium-difficult SQL that uses nested subqueries or CTEs and window functions.

Use the provided PostgreSQL tables. Return monthly author-level results for months containing at least two posts, including each author's post count, total vote score, previous qualifying month score, and rank within the month.

Output

  1. One row per qualifying author and month
  2. Columns: month_start, username, post_count, total_score, previous_month_score, monthly_rank
  3. Sort by month_start ascending, monthly_rank ascending, then username ascending; tied scores share a rank

Schema

reddit_users
ColumnTypeDescription
user_idPKINTUnique Reddit user identifier
usernameVARCHAR(50)Reddit username
reddit_posts
ColumnTypeDescription
post_idPKINTUnique post identifier
author_idINTUser who authored the post
created_atDATEPost creation date
subredditVARCHAR(50)Subreddit where the post appeared
reddit_votes
ColumnTypeDescription
vote_idPKINTUnique vote identifier
post_idINTPost receiving the vote
voter_idINTUser who cast the vote
vote_valueINTVote value, normally 1 or -1
Tablesreddit_usersreddit_postsreddit_votes
Interviewer

Your question is SQL Live Coding With CTEs. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.