Created
June 16, 2021 23:08
-
-
Save ejangi/416aacf9d7b64178b0219757e37fb102 to your computer and use it in GitHub Desktop.
Use the LAG() function to include details about the previous record in a series.
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 | |
ocr.ContactId, | |
ocr.OpportunityCloseDate, | |
ocr.OpportunityAmount, | |
LAG(ocr.OpportunityCloseDate, 1) OVER (PARTITION BY ocr.ContactId ORDER BY ocr.OpportunityCloseDate ASC) AS `Prev` | |
FROM | |
`OpportunityContactRoles` AS ocr | |
WHERE | |
ocr.OpportunityAmount > 0 | |
ORDER BY | |
ocr.OpportunityCloseDate ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment