A logistics company stores delivery data in BigQuery with columns: delivery_date, delivery_id, warehouse_id, and delivery_time_minutes. They want to identify delivery anomalies by finding the delivery time that is greater than the 95th percentile within each warehouse. Which BigQuery SQL function best enables this comparison?
- A. STDDEV(delivery_time_minutes) OVER (PARTITION BY warehouse_id)
- B. PERCENTILE_CONT(delivery_time_minutes, 0.95) OVER (PARTITION BY warehouse_id)✓ Correct
- C. PERCENT_RANK() OVER (PARTITION BY warehouse_id ORDER BY delivery_time_minutes)
- D. NTILE(100) OVER (PARTITION BY warehouse_id ORDER BY delivery_time_minutes)
Explanation
PERCENTILE_CONT() is the correct function to compute the 95th percentile value within each warehouse partition, allowing direct comparison of individual delivery times against that threshold. PERCENT_RANK() returns a rank value (0–1) rather than the actual percentile value. NTILE(100) divides data into 100 buckets but doesn't directly compute a percentile value. STDDEV() computes standard deviation, not percentiles. The window function approach with PARTITION BY warehouse_id ensures the calculation is done independently for each warehouse.