Created
February 19, 2014 18:37
-
-
Save kevinjqiu/9098536 to your computer and use it in GitHub Desktop.
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 | |
"transaction".id, "transaction".amount, | |
"transaction".currency, current_status.status | |
FROM "transaction" JOIN ( | |
SELECT | |
transaction_id, MAX(id) AS max_id | |
FROM transaction_history | |
GROUP BY transaction_id) max_ids JOIN ( | |
SELECT | |
id, transaction_id, status | |
FROM | |
transaction_history) current_status | |
WHERE | |
"transaction".id = max_ids.transaction_id | |
AND "transaction".id = current_status.transaction_id | |
AND max_ids.max_id = current_status.id | |
AND current_status.status = 'processing'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment