Skip to content

Instantly share code, notes, and snippets.

@chasewoodford
Created February 17, 2016 21:10
Show Gist options
  • Save chasewoodford/fe3b0406765ea73fa7eb to your computer and use it in GitHub Desktop.
Save chasewoodford/fe3b0406765ea73fa7eb to your computer and use it in GitHub Desktop.
-- When you need to find the submitted datetime of the second interaction submitted by each and every doc in our database
LEFT JOIN (
SELECT *
FROM (
SELECT
ROW_NUMBER() OVER(PARTITION BY [PhysicianID] ORDER BY [WhenSubmitted]) AS ROW,
[PhysicianID],
[WhenSubmitted]
FROM [dbo].[Recording]
) AS tmp
WHERE ROW = 2
) AS tmp2
ON tmp2.[PhysicianID]=dr.[UID]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment