Created
July 29, 2018 04:40
-
-
Save trankimvu/ef7b8e3fa73b31521c7dbfbc5860147d 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 in_transactions.*, out_transactions.transaction_date as selling_date, DATE_PART('day', out_transactions.transaction_date::timestamp - in_transactions.transaction_date::timestamp) as num_of_holding_days, out_transactions.command_type as selling_command_type | |
FROM "transaction" as in_transactions | |
JOIN "transaction" as out_transactions | |
ON out_transactions.command_type = 'Bán' AND | |
out_transactions.transaction_date = | |
(SELECT MIN (inner_transaction.transaction_date) | |
FROM "transaction" as inner_transaction | |
WHERE inner_transaction.command_type = 'Bán' AND | |
inner_transaction.transaction_date >= in_transactions.transaction_date | |
) | |
ORDER BY in_transactions.transaction_date | |
LIMIT 50; | |
SELECT transaction_date as selling_transaction_date | |
FROM "transaction" | |
WHERE "command_type" = 'Bán' | |
ORDER BY transaction_date | |
LIMIT 50; | |
SELECT * | |
FROM "transaction" | |
WHERE "command_type" = 'Mua' OR "command_type" = 'Switch In' | |
LIMIT 50; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment