Find Customers Whose Average Website Resource Usage Exceeds 50 Percent
Practice PostgreSQL aggregation with HAVING, customer-level average resource utilization, strict thresholds, two-decimal rounding, and ascending email output.
Write one read-only PostgreSQL query that reports customers whose average website resource usage exceeds 50 percent.
Schema
Table
Column
Type
Meaning
customers
id
INT
Primary key
customers
email
VARCHAR(255)
Customer email
site_metrics
customer_id
INT
Foreign key to customers.id
site_metrics
cpu_usage
DECIMAL(5,2)
CPU usage percentage
site_metrics
memory_usage
DECIMAL(5,2)
Memory usage percentage
site_metrics
disk_usage
DECIMAL(5,2)
Disk usage percentage
Task
Calculate each customer's average CPU, memory, and disk usage across all of that customer's site-metric rows. Return one row per qualifying customer, even if customers share an email address.
Include a customer if at least one of the three averages, before rounding, is strictly greater than 50. Apply this condition to the aggregated customer results with HAVING; do not filter individual metric rows by resource usage before averaging.
Return the columns email, average_cpu_usage, average_memory_usage, and average_disk_usage, in that order. Round each displayed average to two decimal places.
Sort rows by email in ascending order. The relative order of rows with the same email is unspecified.
Find Customers Whose Average Website Resource Usage Exceeds 50 Percent
Table customers
column
type
constraints
id
INTEGER
PRIMARY KEY
email
VARCHAR(255)
Sample data:
0
1
1
zoe@example.test
2
amy@example.test
3
li@example.test
4
quiet@example.test
Table site_metrics
column
type
constraints
customer_id
INTEGER
REFERENCES customers(id)
cpu_usage
DECIMAL(5,2)
memory_usage
DECIMAL(5,2)
disk_usage
DECIMAL(5,2)
Sample data:
0
1
2
3
1
20
35
60
1
40
35
70
2
70
20
20
2
10
20
20
3
10
55
20
3
10
65
20
Expected output
email
average_cpu_usage
average_memory_usage
average_disk_usage
li@example.test
10
60
20
zoe@example.test
30
35
65
Hints
Keep each customer's metric rows together when calculating resource averages.
Compare the underlying averages with the threshold before formatting the displayed values.