/*
You are a data analyst working for a logistics company.
Your task is to analyze the delivery time efficiency of the delivery agents.
The company's database contains a table named `deliveries`, which has the following schema:
Schema:
| Column Name | Data Type | Description |
|---------------------|---------------|------------------------------------------------------|
| delivery_id | INT | Unique ID for each delivery |
| agent_name | VARCHAR(15) | Name of the delivery agent |
| total_distance_km | INT | Total distance covered for the delivery (in km) |
| total_time_hours | INT | Total time taken to complete the delivery (in hours) |
| delivery_status | VARCHAR(10) | Status of the delivery (Completed/Delayed/Failed) |
Task:
1. Calculate the efficiency score for each delivery as the square root of the total distance divided by the total time.
2. Identify the top-performing delivery agents based on their efficiency scores, where the efficiency score is greater than 2.
3. Display the following columns:
- `delivery_id`
- `agent_name`
- `efficiency_score`
- `delivery_status`
Expected Output:
| delivery_id | agent_name | efficiency_score | delivery_status |
|-------------|--------------|------------------|-----------------|
| 1 | John Doe | 2.24 | Completed |
| 4 | Emily Smith | 2.12 | Completed |
*/
CREATE TABLE deliveries (
delivery_id INT,
agent_name VARCHAR(15),
total_distance_km INT,
total_time_hours INT,
delivery_status VARCHAR(10)
);
INSERT INTO deliveries (delivery_id, agent_name, total_distance_km, total_time_hours, delivery_status) VALUES
(1, 'John Doe', 50, 10, 'Completed'),
(2, 'Jane Roe', 40, 12, 'Delayed'),
(3, 'Mike Brown', 60, 30, 'Failed'),
(4, 'Emily Smith', 80, 18, 'Completed'),
(5, 'Chris Adams', 100, 60, 'Delayed'),
(6, 'Anna Taylor', 90, 50, 'Completed');
SELECT
delivery_id,
agent_name,
ROUND(SQRT(total_distance_km / total_time_hours), 2) AS efficiency_score,
delivery_status
FROM deliveries
WHERE SQRT(total_distance_km / total_time_hours) > 2
ORDER BY efficiency_score DESC;
To embed this program on your website, copy the following code and paste it into your website's HTML: