Temporary Tables
Factory Location Identification
Use longitude and latitude data to determine the city, state, and region of each factory.
Proximity Analysis
Query the top 10 states closest to each factory.
/2
Revenue Analysis for Top States
Temporary tables
For each factory, retrieve the top 10 states by revenue along with their proximity rankings with 1 being the closest and n being the farthest.
Calculate the average distance of these top 10 states by revenue for each factory.
Determine the percentage of total sales contributed by the top 10 states for each factory.
Factory Reassignment
For each product, calculate the average delivery distance to the top 10 revenue-generating states and identify the top 5 nearest factories.
This query evaluates potential new factory-product pairings by a) finding the average delivery distance for the top 5 states by revenue and their percentage contribution to the product's total revenue, and b) comparing the current factory’s average distance and recommending a new factory based on proximity and efficiency.