← AkunaCapital Interview Insights
The UNION ALL part felt obvious but I second-guessed myself on whether to use UNION vs UNION ALL.
Write two separate SELECT statements, one for CPU and one for Memory, each filtering for February 2024, grouping by application_id, and using HAVING to keep only averages above 50. Then combine them with UNION ALL, and finally sort by application_id and resource type.
Pro tip: Mention that using UNION ALL instead of UNION avoids unnecessary deduplication overhead, which is important for large datasets. Also, clarify that the date filter should be applied before aggregation to reduce the number of rows processed.
For each table, apply a WHERE clause to restrict to February 2024, then GROUP BY application_id and compute AVG(usage_percentage).
Use HAVING AVG(usage_percentage) > 50 to keep only groups where the average exceeds 50%.
In each SELECT, include a literal column for the resource type ('CPU' or 'Memory') and round the average to the desired precision (e.g., 2 decimal places).
Use UNION ALL to merge the two result sets, ensuring column order and data types match.
Add an ORDER BY clause to sort by application_id and then by resource type (or type as specified).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.