cswork / libraryOpen practice workspace

Interview experiences · IBM

IBM Software Engineer Interview Experience — PostgreSQL Averages and HAVING for Resource Usage

OAInterviewed 2026-08

Write a PostgreSQL query to identify customers whose websites have excessively high average resource usage. Table schemas: The customers table contains id (INT, primary key) and email (VARCHAR(255)). The site_metrics table contains customer_id (INT, foreign key), cpu_usage (DECIMAL(5,2)), memory_usage (DECIMAL(5,2)), and disk_usage (DECIMAL(5,2)). Specific requirements: The report must show custo…

Write a PostgreSQL query to identify customers whose websites have excessively high average resource usage.
Table schemas:

  1. The customers table contains id (INT, primary key) and email (VARCHAR(255)).
  2. The site_metrics table contains customer_id (INT, foreign key), cpu_usage (DECIMAL(5,2)), memory_usage (DECIMAL(5,2)), and disk_usage (DECIMAL(5,2)). Specific requirements:
  3. The report must show customers whose average usage exceeds 50% for any resource: CPU, memory, or disk.
  4. The result must include email, average_cpu_usage (average CPU usage, rounded to 2 decimal places), average_memory_usage (average memory usage, rounded to 2 decimal places), and average_disk_usage (average disk usage, rounded to 2 decimal places).
  5. Sort the results by email in ascending order (ASC).
  6. Filtering logic: First calculate each customer's average usage across all websites, then select customers for whom average_cpu_usage > 50 or average_memory_usage > 50 or average_disk_usage > 50. That means using HAVING to filter the aggregated results, rather than using WHERE during the JOIN to filter individual records.

Comments

Nothing here yet.

Join in on CSWork →