R
Rafi
I have two tables with Tbl_A having close to a million records of shipments
out of 6 different warehouses (Origin) to multiple destinations (two columns
Origin and Destination) and Tbl_B which has the transit time for each
origin-Destination pair (three columns: Origin, Destination and Transit
(time).
What I need to do is as follows:
1) find out which of the records in table a will have a transit time over
two days
2) find out which of those records above can be shipped in two days if we
changed the origin to another warehouse)
I have two queries that do the job; however, my second query results in
multiple combination (origin destination) that meet the two days requirement.
I want to show only one record (Min) or if there are two records with an
identical transit time show the first of the two.
Step -1 Find the transit time for each pair
SELECT Q3_Shipments.ID, GND_TRANSIT.Origin, GND_TRANSIT.DEST_ZIP,
GND_TRANSIT.[SERVICE DAYS]
FROM GND_TRANSIT INNER JOIN Q3_Shipments ON (GND_TRANSIT.DEST_ZIP =
Q3_Shipments.CUST_ZIP) AND (GND_TRANSIT.Origin = Q3_Shipments.[Origin Zip])
ORDER BY GND_TRANSIT.Origin;
SELECT Q_OD_Transit_Time.ID, Q_OD_Transit_Time.Origin,
Q_OD_Transit_Time.DEST_ZIP, Q_OD_Transit_Time.[SERVICE DAYS]
FROM Q_OD_Transit_Time
WHERE (((Q_OD_Transit_Time.[SERVICE DAYS])>2));
Step 2 - Determine which is over two days
SELECT Q_OD_Transit_Time.ID, Q_OD_Transit_Time.Origin,
Q_OD_Transit_Time.DEST_ZIP, Q_OD_Transit_Time.[SERVICE DAYS]
FROM Q_OD_Transit_Time
WHERE (((Q_OD_Transit_Time.[SERVICE DAYS])>2));
Steo 3 - determine a new origin
SELECT [Q_TRANSIT OVER 2].Origin AS [Current], GND_TRANSIT.Origin AS
Proposed, [Q_TRANSIT OVER 2].DEST_ZIP, [Q_TRANSIT OVER 2].[SERVICE DAYS] AS
Current_Days, Min(GND_TRANSIT.[SERVICE DAYS]) AS Proposed_Days
FROM [Q_TRANSIT OVER 2] INNER JOIN GND_TRANSIT ON [Q_TRANSIT OVER
2].DEST_ZIP = GND_TRANSIT.DEST_ZIP
GROUP BY [Q_TRANSIT OVER 2].Origin, GND_TRANSIT.Origin, [Q_TRANSIT OVER
2].DEST_ZIP, [Q_TRANSIT OVER 2].[SERVICE DAYS]
HAVING (((Min(GND_TRANSIT.[SERVICE DAYS]))<=2));
Thanks for your help
out of 6 different warehouses (Origin) to multiple destinations (two columns
Origin and Destination) and Tbl_B which has the transit time for each
origin-Destination pair (three columns: Origin, Destination and Transit
(time).
What I need to do is as follows:
1) find out which of the records in table a will have a transit time over
two days
2) find out which of those records above can be shipped in two days if we
changed the origin to another warehouse)
I have two queries that do the job; however, my second query results in
multiple combination (origin destination) that meet the two days requirement.
I want to show only one record (Min) or if there are two records with an
identical transit time show the first of the two.
Step -1 Find the transit time for each pair
SELECT Q3_Shipments.ID, GND_TRANSIT.Origin, GND_TRANSIT.DEST_ZIP,
GND_TRANSIT.[SERVICE DAYS]
FROM GND_TRANSIT INNER JOIN Q3_Shipments ON (GND_TRANSIT.DEST_ZIP =
Q3_Shipments.CUST_ZIP) AND (GND_TRANSIT.Origin = Q3_Shipments.[Origin Zip])
ORDER BY GND_TRANSIT.Origin;
SELECT Q_OD_Transit_Time.ID, Q_OD_Transit_Time.Origin,
Q_OD_Transit_Time.DEST_ZIP, Q_OD_Transit_Time.[SERVICE DAYS]
FROM Q_OD_Transit_Time
WHERE (((Q_OD_Transit_Time.[SERVICE DAYS])>2));
Step 2 - Determine which is over two days
SELECT Q_OD_Transit_Time.ID, Q_OD_Transit_Time.Origin,
Q_OD_Transit_Time.DEST_ZIP, Q_OD_Transit_Time.[SERVICE DAYS]
FROM Q_OD_Transit_Time
WHERE (((Q_OD_Transit_Time.[SERVICE DAYS])>2));
Steo 3 - determine a new origin
SELECT [Q_TRANSIT OVER 2].Origin AS [Current], GND_TRANSIT.Origin AS
Proposed, [Q_TRANSIT OVER 2].DEST_ZIP, [Q_TRANSIT OVER 2].[SERVICE DAYS] AS
Current_Days, Min(GND_TRANSIT.[SERVICE DAYS]) AS Proposed_Days
FROM [Q_TRANSIT OVER 2] INNER JOIN GND_TRANSIT ON [Q_TRANSIT OVER
2].DEST_ZIP = GND_TRANSIT.DEST_ZIP
GROUP BY [Q_TRANSIT OVER 2].Origin, GND_TRANSIT.Origin, [Q_TRANSIT OVER
2].DEST_ZIP, [Q_TRANSIT OVER 2].[SERVICE DAYS]
HAVING (((Min(GND_TRANSIT.[SERVICE DAYS]))<=2));
Thanks for your help