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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
SQL Joins for Web Traffic Data
00:00
5 left

SQL Joins for Web Traffic Data

MediumSQL · PostgreSQL

Problem

Question on web monthly traffic data with multiple tables. It required joining tables and fetching the traffic data based on some criteria. Coding questions were based on distributed servers with power of 2 load capability. Very similar to what other internship candidates have mentioned here.

Write a query for active pages belonging to North America sites during January and February 2025, retaining site-month totals of at least 1,000 visits.

Output

  1. One row per qualifying site and month with site_name, month_start, total_visits, and page_count
  2. Include only qualifying site-months, ordered by site_name, then month_start

Output details

  • Treat month_start as dates from 2025-01-01 inclusive through 2025-03-01 exclusive.
  • Compute total_visits as the sum of visits for each site-month.
  • Compute page_count as the number of distinct page_id values for each site-month.
  • Order by site_name ascending, then month_start ascending.

Schema

sites
ColumnTypeDescription
site_idPKINTUnique site identifier
site_nameVARCHAR(100)Name of the website
regionVARCHAR(50)Geographic region assigned to the site
web_pages
ColumnTypeDescription
page_idPKINTUnique page identifier
site_idINTSite containing the page
page_nameVARCHAR(100)Page label
is_activeBOOLEANWhether the page is currently active
monthly_traffic
ColumnTypeDescription
traffic_idPKINTUnique traffic record identifier
page_idINTPage receiving the traffic
month_startDATEFirst day of the traffic month
visitsINTNumber of recorded visits
Tablessitesweb_pagesmonthly_traffic
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.