MYSQL - combining 2 time series
العربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I am working with price data for futures contracts. I have data for Dec. 2010 and Mar. 2011, that I have loaded into the db. I want to generate a flat file with the time series that includes both contracts. So, let's say Dec. 2010 expires on Dec. 31, 2010. On that day I will switch to the prices from the Mar. '11 contract. Before that, I do not want to capture the Mar. 11 contract. I know how to do the first step of the process, i.e. get the data for the Dec. 2010 contract, but I am trying to figure out if I should run a separate query and append to the data file, or is there a way I can modify my SQL to handle the above. This is the code I have written in my perl file.
my $sql=SELECT c_name, t_date, t_price,t_volume FROM $tblname where c_name='FZ10';
If I write a second query, that will be:
my $sql=SELECT c_name, t_date, t_price,t_volume FROM $tblname where c_name='FH11';
my $sth = $dbh->prepare($sql) or die $dbh->errstr;
$sth->execute or die $sth->errstr;
open(FOUT, "> prices.dat");
Can you please let me know what is the best way to combine these 2 time series (given the date constraints) into a flat file. thx!
Answer |
What you are looking for is the UNION operator. Try that query:
SELECT c_name, t_date, t_price,t_volume FROM $tblname where c_name='FZ10'
UNION
SELECT c_name, t_date, t_price,t_volume FROM $tblname where c_name='FH11'