My issue
SELECT
r.lane_id,
n.origin,
n.destination,
r.revenue - (t.cost_per_distance * n.distance) AS profit
FROM
Network n
JOIN
Revenue r on n.connection_id=r.lane_id
join
Truck t on n.truck_id=t.truck_id
WHERE
n.truck_id = ‘Truck2’ group by r.lane_id
ORDER BY
profit DESC;
My code
/* Write a query to do the following
- We need to output the following - 'lane_id', 'origin', 'destination', and compute 'profit'
- Order by decreasing 'profitability'
- 'profit' is the alias for the column which stores the values 'Revenue' - 'running_cost'
- 'running_cost' is computed as (cost_per_distance x distance)
- **Hint:** you will need to use join all the tables - 'Revenue', 'Truck' and 'Network' and apply relevant conditions
- **Hint:** This has to be computed only for the truck_type 'medium' */
SELECT
r.lane_id,
n.origin,
n.destination,
r.revenue - (t.cost_per_distance * n.distance) AS profit
FROM
Network n
JOIN
Revenue r on n.connection_id=r.lane_id
join
Truck t on n.truck_id=t.truck_id
WHERE
n.truck_id = 'Truck2' group by r.lane_id
ORDER BY
profit DESC;
Learning course: Learn Data Analytics using SQL and Python
Problem Link: CodeChef: Practical coding for everyone