Answer:
SELECT
MIN(warehouse_size) AS smallest_warehouse,
MAX(warehouse_size) AS largest_warehouse,
customer_id,
COUNT(*) AS num_warehouses
FROM
warehouse_table
GROUP BY
customer_id
ORDER BY
num_warehouses ASC, warehouse_size ASC
Step-by-step explanation:
This query retrieves the minimum and maximum warehouse sizes across all customers, as well as the number of warehouses owned by each customer. The GROUP BY clause groups the results by the customer_id column, while the MIN, MAX, and COUNT functions aggregate the data for each customer.
The results are ordered by ascending order of the number of warehouses owned (num_warehouses) and then by ascending order of the warehouse size (warehouse_size). This allows us to identify the customers who own the smallest and largest warehouses, as well as those who own the fewest and most warehouses.