Created
June 16, 2021 23:05
-
-
Save jamesasu/7364549c70d726eb746fdd3f5a0d5416 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 hidden or 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