The Friday Purchases I coding problem is a SQL task where you are given a table of purchases containing a purchase date and an amount. You need to calculate the total amount spent on purchases made exactly on Fridays, grouped by each week of a specific month (e.g., November 2023). The output should list the week number and the total Friday spending for that week.
Companies like TCS use this Database interview pattern to evaluate a candidate's proficiency with date and time functions in SQL. Extracting specific days of the week and calculating week numbers within a month are very common tasks in business reporting and ETL pipelines. It tests your ability to filter, group, and aggregate time-series data accurately.
The problem is solved using Date Functions and Aggregation.
WHERE clause to restrict the data to the specific month/year required.DAYOFWEEK(), WEEKDAY(), or TO_CHAR() to keep only purchases made on a Friday.CEIL(DAY(purchase_date) / 7) or similar DB-specific logic).GROUP BY the calculated week number and SUM the purchase amounts.Purchases in Nov 2023:
DAYOFWEEK vs EXTRACT(DOW FROM date)).WEEK()) map perfectly to "Week 1, Week 2 of the month," which is usually not the case. Dividing the day of the month by 7 is usually required.GROUP BY will fail. You would need a LEFT JOIN against a static table of week numbers.Always clarify which SQL dialect (MySQL, Postgres, SQL Server) the interviewer expects, as date functions are the least standardized part of SQL. Practice extracting the day of the week and the week of the month.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Second Highest Salary | Medium | Solve | |
| Active Businesses | Medium | Solve | |
| Active Users | Medium | Solve | |
| Activity Participants | Medium | Solve | |
| All People Report to the Given Manager | Medium | Solve |