Skip to content
Advertisement

How to do select insert into statements and handling time series data and foreign keys?

I am completely lost on how to approach the problem I am having. I am trying to generate a boolean statement from one table and insert it into another table’s column. I am able to generate the boolean statement and create a new column as shown with the code and output below:

 SELECT date_price, stock_id, (adj_close_price>ub1_50_d) as d20_l_d50
 FROM bollinger_bands
 LIMIT 100; 

Boolean output

This is what I have so far:

INSERT INTO decisions (stock_id,
                   date_price,  
                   created_date,
                   last_updated_date,
                   d20_l_d50)
 VALUES         
                   ( ,
                     ,
                   now(),
                   now(),
                   (SELECT adj_close_price > ub1_50_d as d20_l_d50
                   FROM bollinger_bands)
                   );
                   

Current decision table

I am stuck on how to insert the boolean output into another table’s column. Two columns I am particularly unclear on are: the date column and the stock_id column. I don’t even know if I am on the right path at this point and what to look for. Any assistance and suggestions are appreciated.

Advertisement

Answer

Get rid of the values clause:

INSERT INTO decisions (stock_id,date_price,created_date, last_updated_date, d20_l_d50)
select date_price, stock_id, now(), now(), adj_close_price > ub1_50_d
FROM bollinger_bands;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement