Answer the question
In order to leave comments, you need to log in
How to make a selection from 4 tables into 1 PostgreSQL table?
There are 4 SQL tables.
Let's call them BTC_BUY, BTC_SELL, ETH_BUY, ETH_SELL.
Each table has 2 fields UNIXDATE, AMOUNT.
We need to make one table
UNIXDATE, ACTION, CURRENCY, AMOUNT
where ACTION is just a BUY or SELL record, depending on which table we selected the data from.
where CURRENCY is a BTC or ETH entry depending on which table is from.
Sort by UNIXDATE in ascending order.
Answer the question
In order to leave comments, you need to log in
So it is possible:
INSERT INTO RESULTS (UNIXDATE, ACTION, CURRENCY, AMOUNT)
SELECT bb.UNIXDATE, 'BUY', 'BTC', bb.AMOUNT FROM BTC_BUY bb
UNION ALL
SELECT bs.UNIXDATE, 'SELL', 'BTC', bs.AMOUNT FROM BTC_SELL bs
UNION ALL
SELECT eb.UNIXDATE, 'BUY', 'ETH', eb.AMOUNT FROM ETH_BUY eb
UNION ALL
SELECT es.UNIXDATE, 'SELL', 'ETH', es.AMOUNT FROM ETH_SELL es
ORDER BY UNIXDATE ASC;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question