Employees Joined per Month
Reported by candidates from Odoo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The brute-force worry here isn't input size, it's the temptation to build a 12-month calendar and left join against it. Don't. This Odoo SQL question, reported in September 2024, wants one row per month that actually has employees, named and sorted in calendar order. It's a plain GROUP BY with a month-name conversion and a careful ORDER BY. If your mind goes blank on the date functions mid-assessment, StealthCoder runs invisibly on your desktop and hands you the query as a safety net. The logic itself is short.
The problem
An employees table contains one row per employee: employee_id: the employee's unique integer identifier. joining_date: the employee's joining date. For this exercise, assume all joining_date values in one testcase belong to the same calendar year. Return one row for each calendar month represented in the table. Each row must contain: month_name: the English name of the month. employee_count: the number of employees who joined in that month. Do not return months with no employees. If the input table is empty, return an empty result. Sort the rows by calendar month from January through December. Tables employees: employee_id PK (Integer), joining_date (Date) Constraints employee_id is unique and non-null. joining_date is a valid, non-null date. All joining dates in one testcase are from the same calendar year. The result columns must be named month_name and employee_count.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is grouping by the month number, then converting to a name for display. Group by MONTH(joining_date) and select the month name plus COUNT(employee_id) as employee_count. Sort by the month number, never by month_name. Sorting by name gives April, August, December and so on, which fails the test. The pitfall is dialect: MONTHNAME works in MySQL, TO_CHAR(joining_date, 'Month') works in PostgreSQL and pads with trailing spaces, so wrap it in TRIM. Since all dates share one year, you don't need to group by year. An inner aggregation naturally skips empty months and returns nothing on an empty table, which is what the spec asks. Don't add a calendar table or a LEFT JOIN. If the syntax slips away during the live OA, StealthCoder is the hedge that gives you the exact function names.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Employees Joined per Month cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Odoo's OA.
Odoo reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Employees Joined per Month FAQ
How hard is the Odoo Employees Joined per Month question really?+
Easy. It's one table, one aggregate, one sort. The only real risk is the month-name function for your SQL dialect and sorting by the wrong column. If you know GROUP BY and a date-part function, you're done in a few minutes.
What's the trick to getting the sort order right?+
Order by the numeric month, like MONTH(joining_date), not by month_name. Alphabetical sorting puts April first and January fourth. If your dialect requires it, include the month number in GROUP BY so the ORDER BY is valid.
Do I need to return months with zero employees?+
No. The problem says not to return months with no employees, so skip any calendar table or LEFT JOIN. A plain GROUP BY only emits months that exist in the data, and an empty table gives an empty result automatically.
Do I need to group by year too?+
No. The constraints say every joining_date in a testcase is from the same calendar year. Grouping by month alone is enough. Adding year is harmless but unnecessary, and it can complicate your ORDER BY if you're not careful.
How do I prepare for this in 48 hours?+
Rehearse a handful of GROUP BY queries with date functions in your target dialect. Know how to get month number and month name, and practice ordering by the number. Check your column aliases match exactly: month_name and employee_count.