EasyFundamentals
Expiring SaaS Free Trials (7-Day Conversion Window)
Frequently Asked By:MicrosoftGoogleStripe
Interactive In-Browser Workspace
Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.
Problem Statement
Write a query to retrieve all trial accounts in `saas_trials` where:
- `days_until_expiration BETWEEN 1 AND 7`
- `total_logins >= 5`
Return:
1. `account_id`
2. `org_name`
3. `days_until_expiration`
4. `total_logins`
Order results by `days_until_expiration` ascending, then by `total_logins` descending.
Why Technical Interviewers Ask This
Product-led growth (PLG) sales teams reach out to high-engagement trial accounts whose 14-day trials expire within the next 7 calendar days to offer discounted annual contracts.
Common Pitfalls & Interview Traps
Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass fundamentals constructs.
Canonical Modern SQL Solution
PostgreSQL 16 / ANSI SQLSELECT
account_id,
org_name,
days_until_expiration,
total_logins
FROM saas_trials
WHERE days_until_expiration BETWEEN 1 AND 7
AND total_logins >= 5
ORDER BY days_until_expiration ASC, total_logins DESC;Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Fundamentals. It meets the target criteria: High-engagement SaaS trials approaching expiration.Edge Cases to Verbally Clarify with Your Interviewer
The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.
Frequently Asked Follow-Up Questions
What makes this question a favorite among Microsoft and Google interviewers?
Interviewers use this problem to test whether candidates write defensive, scalable Fundamentals queries that run efficiently on multi-million row production databases without excessive memory usage.
How does the query optimizer execute this query?
Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.