Interview Prep

5 SQL Date Patterns for Interviews

Month-over-month growth, rolling averages, cohorts, weekday splits, days-between events: the 5 SQL date patterns analyst JDs repeat, with queries.

Anuj SainiSep 28, 20261 min read
  1. Month-over-month growth — DATE_TRUNC('month', d) + LAG(SUM(rev)) OVER (...). The single most-asked pattern.
  2. Rolling 7/30-day averages — AVG(x) OVER (ORDER BY d ROWS BETWEEN 6 PRECEDING AND CURRENT ROW).
  3. Cohort retention — signup-month × activity-month matrix, DATE_TRUNC on both sides.
  4. Weekday vs weekend — EXTRACT(DOW FROM d) (0 = Sunday; confirm your dialect).
  5. Days between events — ship_date - order_date with WHERE ship_date IS NOT NULL. NULL handling decides it.

Learn these five cold and you cover nearly every take-home and live SQL round. Drill them on messy data at Topfolio Practice.

Related: Sql Window Function Traps · Sql 30 Interview Questions Practice

Frequently Asked Questions

What is the most-asked SQL date pattern?

Month-over-month growth with DATE_TRUNC plus LAG. Learn it cold before anything else.

Why do rolling averages trip people up?

They need a window frame (ROWS BETWEEN), which GROUP BY alone can't express.

DATE_TRUNC or EXTRACT first?

DATE_TRUNC for bucketing months and cohorts; EXTRACT for weekday splits and parts. Both appear constantly.

Anuj Saini

Written by

Anuj SainiFounder & Lead Instructor

Founder at Topfolio with 6+ years in data & analytics across JPMC, Ultrahuman, and high-growth startups. Sat on hiring panels, reviewed 500+ resumes, and writes practical SQL & data guides.