SQL Coding Challenges

Published:

Overview

Goal: Maintain strong, interview-ready SQL fluency in parallel with flagship projects through short, focused challenges.
Each entry captures the problem type and the key SQL pattern(s) used, building a lightweight evidence trail of consistent practice.


Approach

  • Solve short, interview-style SQL problems (e.g., DataLemur).
  • Emphasis on:
    • Correctness under edge cases (duplicates, ties, NULLs, missing dates).
    • Clear query structure (CTEs, readable joins, well-scoped window functions).
    • Reusable mental patterns (Top-N per group, retention, rolling metrics, de-dup).

Focus Areas

  • Joins & Anti-joins: existence checks, missing records, deduped joins
  • CTEs: multi-step transformations, readability, intermediate validation
  • Window Functions: rank/dense_rank, lag/lead, rolling aggregations
  • Time Series: daily/weekly aggregates, rolling windows, period comparisons
  • Cohorts & Funnels: retention, conversion, step drop-off

Challenge Log

Adding new challenges as I am completing them. Keep notes short and pattern-focused.

#DatePlatformSourceChallengeDifficultyCore Pattern(s)Notes
0120/12/2025DataLemurTwitterHistogram of TweetsEasyCTE, group_by, histogramTwo-stage aggregation: tweets/user → users/bucket
0220/12/2025DataLemurLinkedInData Science SkillsEasygroup_by, having, set_filterFilter to required skills, then HAVING count = 3
0320/12/2025DataLemurFacebookPage With No LikesEasyleft_join, COALESCE, zero_countLeft join + COALESCE to treat NULL likes as 0
0420/12/2025DataLemurTeslaUnfinished PartsEasyNULL_filterWHERE finish_date IS NULL
0520/12/2025DataLemurUberUser’s Third TransactionMediumwindow_row_number, CTERow-number per user by date; filter rn = 3
0620/12/2025DataLemurFAANGSecond Highest SalaryMediumdense_rank, dedup_tiesDistinct salaries + dense_rank; pick rank = 2
0720/12/2025DataLemurSnapchatSending vs. Opening SnapsMediumpivot_case_when, percent_calc, CTEConditional aggregation pivot + % of total time
0820/12/2025DataLemurNY TimesLaptop vs. Mobile ViewershipEasyconditional_aggregation, CASEConditional SUM by device bucket
0922/12/2025DataLemurTwitter3-Day Rolling Average TweetsMediumwindow_avg, order_by, window_frameDaily agg → rolling AVG (ROWS 2 PRECEDING)
1022/12/2025DataLemurGoogleOdd and Even MeasurementsMediumrow_number, FILTER, moduloRow_number per day; SUM(…) FILTER by rn%2
1122/12/2025DataLemurZomatoSwapped Food DeliveryMediumrow_number, CASE, odd_even_swapSwap adjacent rows; keep last row if unpaired
1222/12/2025DataLemurAmazonHighest-Grossing ItemsMediumgroup_by, SUM, rank, partition_bySum spend per product; rank within category; top 2
1322/12/2025DataLemurFacebookAverage Post Hiatus (Part 1)EasyMIN_MAX, date_diff, HAVINGFilter users with 2+ posts; max(date)-min(date)
1423/12/2025DataLemurFAANGTop Three SalariesMediumdense_rank, partition_by, order_byDense-rank salaries per dept; filter rank <= 3
1523/12/2025DataLemurTikTokSignup Activation RateMediumleft_join, conditional_count, ratio_roundConfirmed / total emails via LEFT JOIN; round 2dp
1623/12/2025DataLemurSpotifySpotify Streaming HistoryMediumUNION_ALL, group_by, SUM, date_filterUnion weekly+history; sum plays per user/song
1723/12/2025DataLemurMicrosoftTeams Power UsersEasygroup_by, COUNT, date_filter, LIMITCount msgs in date range; order desc; limit 2
1823/12/2025DataLemurLinkedInDuplicate Job ListingsEasygroup_by, having, COUNT, CTEGroup by company; filter duplicates; count companies
1923/12/2025DataLemurMicrosoftSupercloud CustomerMediumjoin, COUNT_DISTINCT, group_by, compare_to_totalCount distinct categories/customer; keep those = total categories
2024/12/2025LeetCodeLeetCode175. Combine Two TablesEasyleft_join, select_colsLEFT JOIN person→address to keep all persons
2124/12/2025LeetCodeLeetCode176. Second Highest SalaryMediumdistinct, rank, NULL_if_missingDistinct salaries; pick 2nd (else NULL)
2224/12/2025LeetCodeLeetCode177. Nth Highest SalaryMediumdistinct, dense_rank, parameter_fn, NULL_if_missingDense-rank distinct salaries; return rank = N else NULL
2324/12/2025LeetCodeLeetCode178. Rank ScoresMediumdense_rank, order_byDense-rank scores (no gaps); order by score desc
2424/12/2025DataLemurBloombergFAANG Stock Min-Max (Part 1)Mediumgroup_by, MIN_MAX, join_back, format_monthFind min/max open per ticker; join back to get month
2524/12/2025DataLemurRobinhoodCities With Completed TradesEasyjoin, group_by, COUNT, filter, LIMITJoin users→trades; filter completed; top-3 cities by count
2625/12/2025LeetCodeLeetCodeRank ScoresMediumwindow_functions, DENSE_RANKUse DENSE_RANK() to produce gapless ranks with ties; order by score DESC
2725/12/2025LeetCodeLeetCodeConsecutive NumbersMediumwindow_functions, LAG/LEAD, distinctDetect values appearing ≥3 times consecutively via LAG/LEAD (num = prev AND num = next) + DISTINCT

Stack

  • Language: SQL (PostgreSQL-style)
  • Environment: DataLemur + LeetCode + local notes

Impact

  • Keeps SQL fluency current through consistent repetition of high-frequency interview patterns.
  • Reinforces correctness under common edge cases (ties, duplicates, NULL handling).
  • Complements the full-scale SQL portfolio project by demonstrating ongoing practice and readiness.