Skip to content

Instantly share code, notes, and snippets.

@IronistM
Forked from robertjmoore/gist:3960013
Last active August 29, 2015 14:22
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 IronistM/2f453da28617064768b2 to your computer and use it in GitHub Desktop.
Save IronistM/2f453da28617064768b2 to your computer and use it in GitHub Desktop.
SELECT orders.customerid,
orders.transactiondate,
orders.transactionamount,
cohorts.cohortdate
FROM orders
JOIN (SELECT customerid,
Min(transactiondate) AS cohortDate
FROM orders
GROUP BY customerid) AS cohorts
ON orders.customerid = cohorts.customerid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment