Created
August 3, 2021 05:29
-
-
Save aleksejkozin/027f16e4a512e2217a5f4b21867e2f5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM ( | |
SELECT IT.ID, | |
ROW_NUMBER() | |
OVER ( | |
PARTITION BY | |
IT.VendorId, | |
IT.ItemNumber, | |
I.StoreID | |
ORDER BY I.InvoiceDate DESC, IT.InvoiceID DESC | |
) rn, | |
I.InvoiceDate, | |
ItemNumber, | |
It.VendorId, | |
I.StoreID | |
FROM Item IT | |
INNER JOIN Invoice I ON InvoiceID = I.ID | |
WHERE ItemNumber = 'FB100G-1' | |
) t1 | |
WHERE rn = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment