Back to questions

Spare Server Capacity Microsoft SQL Interview Question

Spare Server Capacity

Microsoft SQL Interview Question

Microsoft Azure's capacity planning team wants to understand how much data its customers are using, and how much spare capacity is left in each of its data centers. You’re given three tables: customers, data centers, and forecasted_demand.

Write a query to find each data centre’s total unused server capacity. Output the data center id in ascending order and the total spare capacity.

Definitions:

  • is the total monthly server capacity for each centers.
  • is the server demand for each customer.

P.S. If you've read the Ace the Data Science Interview and liked it, consider writing us a review?

Table:

Column NameType
datacenter_idinteger
namestring
monthly_capacityinteger

Example Input:

datacenter_idnamemonthly_capacity
1London100
3Amsterdam250
4Hong Kong400

Table:

Column NameType
customer_idinteger
datacenter_idinteger
monthly_demandinteger

Example Input:

customer_iddatacenter_idmonthly_demand
1094120
144360
1444105
852160
8523178

Example Output:

datacenter_idspare_capacity
140
312
4175

The dataset you are querying against may have different input & output - this is just an example!

Input

Output