Hello,
I've tried to use this video linked below to use the SQLQuery function. However, I'm having an issue.
community.jmp.com/t5/video/gallerypage/video-id/tvcW9lZTE6Ie3IFXxeru0AYNqvj5AB5r
Problem: Take Table 2 with "cylinder" "Received_Date" and "lot" & merge that into Table 1 that has "batch", "cylinder" and "Batch_Date"
I need to match exactly on "Cylinder" and then take the nearest backward "Received Date" to the "Batch Date" (Batch_Date >= Received_Date).
I created the query & also did the step to create a numeric tag that should theoretically provide only 1 unique lot number for each batch (not shown in table below)
However, this is what I'm getting
Batch | Batch Date | Cylinder Number | Lot Number | Received Date |
1 | 2/13/2023 | 55 | A | 6/14/2022 |
1 | 2/13/2023 | 55 | B | 10/21/2022 |
1 | 2/13/2023 | 55 | C | 11/30/2022 |
There should only be 1 row populated from the query (should be the last row 11/30/2022); the other ones are "ghosts" as we only made 1 "Batch 1"
Any help on how to improve the SQL code to prevent duplicate entries & pick the entry only if the received date is the closest <= batch date?
This was the code from the SQLQuery interface that was given
SELECT DISTINCT t1.Batch, t1.Batch_Date AS Date, t1.Cylinder_Number,
t2.Lot_Number, t2.Cylinder_Number AS "Cylinder_Number 2", t2.Lot_Date AS "Date 2", MIN(t2."Batch Num") AS "Minimum-Batch Num"
FROM "Table 1" t1
LEFT OUTER JOIN "Table 2" t2
ON ( ( t1.Cylinder_Number = t2.Cylinder_Number ) AND ( t1.Cat_Date >= t2.Lot_Date ) )
GROUP BY t1.Batch, t1.Batch_Date, t1.Cylinder_Number,
t2.Lot_Number, t2.Cylinder_Number, t2.Lot_Date;