Created
September 7, 2013 06:31
-
-
Save pichi/6473329 to your computer and use it in GitHub Desktop.
Fastest previous date solution.
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
drop table if exists products; | |
drop table if exists prod; | |
drop table if exists `out`; | |
SET max_heap_table_size = 1024*1024*1024; | |
create table products ( id int not null, partner int not null, start date not null) engine=memory ; | |
load data infile '/tmp/test.data' into table products columns terminated by ','; | |
create table prod ( r int not null AUTO_INCREMENT primary key, rp int default 1, id int not null, partner int not null, start date ) engine=memory as select id, partner, start from products order by partner, start; | |
drop table products; | |
update prod set rp = r-1; | |
create table `out` engine=memory select p1.id, p1.partner, p1.start, p2.start prev from prod p1 left join prod p2 on p2.r = p1.rp and p2.partner = p1.partner; | |
drop table prod; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment