FastPrepCustomer Resource Usage Analysis
Problem · Database

Customer Resource Usage Analysis

EasyIBM logoIBMFULLTIMEOA
See IBM hiring insights

Problem statement

A web-hosting provider tracks resource usage for every customer's sites. Using the customers and site_metrics tables, create a report with email, average_cpu_usage, average_memory_usage, and average_disk_usage.

  • Compute each average across all metric rows belonging to that customer.
  • Include a customer only when at least one unrounded average is strictly greater than 50.
  • Round each returned average to two decimal places.
  • Order rows by email ascending.

For this exercise, customer IDs and emails are unique, every metric row references a customer, and all values are non-null. Customers without metric rows are omitted. Calculate with exact decimals, apply the threshold before rounding, and round halfway values away from zero.

In MySQL and PostgreSQL, write a query over the supplied tables. In Pandas, implement customer_resource_report(customers, site_metrics) and return a DataFrame with the four result columns in the stated order.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

customers

One row per web-hosting customer.

ColumnTypeNullableDescription
idPKIntegerNoUnique customer identifier.
emailTextNoUnique customer email address.

site_metrics

One resource-usage observation for one customer site.

ColumnTypeNullableDescription
customer_idIntegerNoCustomer owning the observed site.
cpu_usageDecimalNoCPU usage percentage.
memory_usageDecimalNoMemory usage percentage.
disk_usageDecimalNoDisk usage percentage.

Foreign key: customer_id customers(id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
emailTextNoCustomer email.
average_cpu_usageDecimalNoAverage CPU usage rounded to two decimals.
average_memory_usageDecimalNoAverage memory usage rounded to two decimals.
average_disk_usageDecimalNoAverage disk usage rounded to two decimals.

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • 0 <= customers.length <= 1000
  • 0 <= site_metrics.length <= 100000
  • Customer IDs are signed 32-bit integers and are unique.
  • Email values are nonempty and unique.
  • CPU, memory, and disk usage are exact decimals from 0 through 100, with at most two fractional digits.
  • Every metric row references an existing customer, and no table cell is null.

More IBM problems