TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #1940 1.78K
Below ๐ˆโ€™๐ฆ ๐ฌ๐ก๐š๐ซ๐ข๐ง๐  ๐Ÿ“ ๐’๐๐‹ ๐ˆ๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ ๐๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง๐ฌ asked in a recent interview for a ๐ƒ๐š๐ญ๐š ๐€๐ง๐š๐ฅ๐ฒ๐ฌ๐ญ ๐ซ๐จ๐ฅ๐ž ๐š๐ญ ๐†๐ž๐ง๐ฉ๐š๐œ๐ญ (๐Ÿโ€“๐Ÿ“ ๐ฒ๐ž๐š๐ซ๐ฌ ๐ž๐ฑ๐ฉ๐ž๐ซ๐ข๐ž๐ง๐œ๐ž):-

๐Ÿ”น Q1. Identify Active Subscriptions in a Given Timeframe
Table: subscriptions(subscription_id, activation_date, deactivation_date)
Find all subscription_ids that were active at any point between '2010-01-01' and '2020-12-31'.
(Note: If deactivation_date is NULL, consider it as still active.)

๐Ÿ”น Q2. Group Continuous Membership Records into Start & End Periods
Table: memberships(user_id, plan_id, valid_till)
This table contains monthly records for users.

Group rows into blocks where a user stayed continuously subscribed to the same plan without missing a month, and return:
user_id, plan_id, start_date, end_date for each such block.

๐Ÿ”น Q3. Count Logins Based on User Status & Lookback Window
Tables: users(user_id, is_active, offboarded_on)
logins(login_id, user_id, login_date)

For each user:
โ†’ If is_active = true, count logins in the last 12 months from '2023-12-01'
โ†’ If is_active = false, count logins in the 12 months before offboarded_on
Return: user_id, status, period_start, period_end, login_count

๐Ÿ”น Q4. Match First Interaction Channel with Final Conversion
Tables: touchpoints(user_id, channel, interaction_date)
conversions(user_id, converted_on, is_converted)

Among users who converted, find how many had their first interaction channel same as the one that led to conversion.
Use min & max interaction dates to identify first and last channels. Return the percentage of such users.

๐Ÿ”น Q5. Find Cross-Category Spenders in Last 6 Months
Tables:
purchases(user_id, product_id, purchase_date)
products(product_id, category)
Find users who bought products from at least 3 different categories in the last 6 months.
Return user_id and count of unique categories.

Tap โค๏ธ for more
  • โค 4
More from @sqlanalyst
  1. Oct 18, 2026๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—ง๐—ผ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ˜ โœ… 100% FREE Yoโ€ฆ
  2. Oct 17, 2026SQL Interview Series โ€” Part 12 ๐Ÿ“Œ Question 12: Find the Department with the Highest Averagโ€ฆ
  3. Oct 17, 2026๐—œ๐—•๐—  ๐—™๐—ฅ๐—˜๐—˜ ๐—ง๐—˜๐—–๐—› ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“ Explore IBM Cognitive Class and buildโ€ฆ
  4. Oct 16, 2026๐——๐—ฎ๐˜๐—ฎ ๐˜€๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ช๐—ถ๐˜๐—ต ๐—”๐—œ๐Ÿ˜ Future Ready Data Scienโ€ฆ
  5. Oct 16, 2026SQL Interview Series โ€” Part 11 ๐Ÿ“Œ Question 11: Calculate a Running Total of Sales Supposeโ€ฆ
  6. Oct 13, 2026SQL Interview Series โ€” Part 8 ๐Ÿ“Œ Question 8: Find Customers Who Have Never Placed an Orderโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’