Tesla interview question
Running sales total per store that resets at the start of each month
- Company:
- Tesla
- Round:
- Phone screen
- Type:
- SQL
- Difficulty:
- Medium
- Reported:
- Q2 2026
Problem
Table sales:
| column | type | description |
|---|---|---|
date | DATE | day of the sale |
store_id | INT | store that made the sale |
amount | DECIMAL(12, 2) | sale amount |
Write a query that returns, for every store and every date on which that store has sales, the cumulative sales amount from the first day of that calendar month up to and including that date. The running total starts again from 0 when a new month begins.
Return the columns store_id, date and total_amount. Any row order is accepted; the reference orders by store_id and then date.
The prompt does not say whether a store can have several rows on the same date. If it can, ask the interviewer whether the output should have one row per store and date (combining those sales) or one row per sale; the reference query combines them.
Example 1
Input: sales
date store_id amount
2024-01-30 1 100.00
2024-01-31 1 75.00
2024-02-01 1 40.00
2024-02-03 1 60.00
2024-01-31 2 70.00
2024-02-02 2 30.00
Output:
store_id date total_amount
1 2024-01-30 100.00
1 2024-01-31 175.00
1 2024-02-01 40.00
1 2024-02-03 100.00
2 2024-01-31 70.00
2 2024-02-02 30.00
Store 1 reaches 175.00 by the end of January. February starts again from 0, so February 1 shows only that day's 40.00, and February 3 adds 60.00 for a total of 100.00.
Constraints
- Months are calendar months of
date; the same month in different years is a different month. - Any SQL dialect with window functions is acceptable; the reference query uses PostgreSQL.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern