Commit 79107eab authored by Robert's avatar Robert
Browse files

financials and pricing load

parent 31efe08b
create table PricingAll (
/* Create strong entity Stock table which holds symbols, will be populated by the csvs later on */
create table Stock (
symbol varchar(6),
primary key (symbol)
);
/********************************************************************************************/
/* LOAD PRICING DATA */
/* Create stock price table */
create table StockPrice (
date datetime,
volume decimal(12, 0),
open decimal(22, 12),
......@@ -6,10 +16,147 @@ create table PricingAll (
low decimal(22, 12),
close decimal(22, 12),
adjClose decimal(22, 12),
symbol varchar(6)
symbol varchar(6),
primary key (symbol, date)
);
load data infile '/var/lib/mysql-files/18-Stocks/fh_5yrs.csv' ignore into table StockPrice
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Populate Stock table using the pricing data */
insert into Stock (symbol)
select distinct symbol
from StockPrice;
/* Add the foreign key constraint */
alter table StockPrice
add foreign key (symbol) references Stock(symbol);
/********************************************************************************************/
/********************************************************************************************/
/* LOAD FINANCIAL DATA */
/* Create financials table */
create table Financials(
symbol varchar(6),
year int,
revenue decimal(16, 2),
revenueGrowth decimal(16, 2),
costOfRevenue decimal(16, 2),
grossProfit decimal(14, 2),
rndExpenses decimal(14, 2),
eps decimal(14, 4),
epsDiluted decimal(14, 4),
dividendPerShare decimal(17, 4),
ebitda decimal(14, 2),
ebit decimal(14, 2),
profitMargin decimal(17, 4),
cashAndEquivalent decimal(14, 2),
debtGrowth decimal(10, 4),
primary key (symbol, year)
);
load data infile '/var/lib/mysql-files/18-Stocks/fh_5yrs.csv' ignore into table PricingAll
fields terminated by ','
enclosed by '"'
lines terminated by '\n';
\ No newline at end of file
/* Create temporary financials table for loading data */
create table FinancialsTemp(
symbol varchar(6),
revenue decimal(16, 2),
revenueGrowth decimal(16, 2),
costOfRevenue decimal(16, 2),
grossProfit decimal(14, 2),
rndExpenses decimal(14, 2),
eps decimal(14, 4),
epsDiluted decimal(14, 4),
dividendPerShare decimal(17, 4),
ebitda decimal(14, 2),
ebit decimal(14, 2),
profitMargin decimal(17, 4),
cashAndEquivalent decimal(14, 2),
debtGrowth decimal(10, 4)
);
/* Load 2014 financial data into db */
load data infile '/var/lib/mysql-files/Group41/2014_Financial_Data_processed_G41.csv' ignore into table FinancialsTemp
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Move 2014 financial data into correct location */
insert into Financials(symbol, year, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth)
select symbol, 2014, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth
from FinancialsTemp;
/* Empty the temp table */
truncate FinancialsTemp;
/* Load 2015 financial data into db */
load data infile '/var/lib/mysql-files/Group41/2015_Financial_Data_processed_G41.csv' ignore into table FinancialsTemp
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Move 2015 financial data into correct location */
insert into Financials(symbol, year, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth)
select symbol, 2015, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth
from FinancialsTemp;
/* Empty the temp table */
truncate FinancialsTemp;
/* Load 2016 financial data into db */
load data infile '/var/lib/mysql-files/Group41/2016_Financial_Data_processed_G41.csv' ignore into table FinancialsTemp
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Move 2016 financial data into correct location */
insert into Financials(symbol, year, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth)
select symbol, 2016, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth
from FinancialsTemp;
/* Empty the temp table */
truncate FinancialsTemp;
/* Load 2017 financial data into db */
load data infile '/var/lib/mysql-files/Group41/2017_Financial_Data_processed_G41.csv' ignore into table FinancialsTemp
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Move 2017 financial data into correct location */
insert into Financials(symbol, year, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth)
select symbol, 2017, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth
from FinancialsTemp;
/* Empty the temp table */
truncate FinancialsTemp;
/* Load 2018 financial data into db */
load data infile '/var/lib/mysql-files/Group41/2018_Financial_Data_processed_G41.csv' ignore into table FinancialsTemp
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
/* Move 2018 financial data into correct location */
insert into Financials(symbol, year, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth)
select symbol, 2018, revenue, revenueGrowth, costOfRevenue, grossProfit, rndExpenses, eps, epsDiluted, dividendPerShare, ebitda, ebit, profitMargin, cashAndEquivalent, debtGrowth
from FinancialsTemp;
/* Empty the temp table */
truncate FinancialsTemp;
drop table FinancialsTemp;
/* Add missing stock tickers to Stock */
insert ignore into Stock (symbol)
select distinct symbol
from Financials;
/* Set up the foreign key restraint on symbol */
alter table Financials
add foreign key (symbol) references Stock(symbol);
/********************************************************************************************/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment