Skip to content

Instantly share code, notes, and snippets.

@MisterPhoton
Created June 10, 2010 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MisterPhoton/433607 to your computer and use it in GitHub Desktop.
Save MisterPhoton/433607 to your computer and use it in GitHub Desktop.
SELECT
sp.invoiceId as 'InvId',
spMin.`date` as 'minDate',
spMax.`date` as 'maxDate'
FROM Guide_Invoice_ScheduledPayments sp
JOIN (SELECT invoiceId, MIN(`date`) as `date` from Guide_Invoice_ScheduledPayments group by invoiceId) as spMin on sp.invoiceId = spMin.invoiceId
JOIN (SELECT invoiceId, MAX(`date`) as `date` from Guide_Invoice_ScheduledPayments group by invoiceId) as spMax on sp.invoiceId = spMax.invoiceId
group by sp.invoiceId
having maxDate > minDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment