我有一个表 table1 ,格式如下
id, company, col1,col2,...
company 里面有同一个公司发生更名情况。
比如 companyA 在 2010-01-01 以前 名字叫 abc , 2010-01-01 更名为 xyz 。
这样的公司可能有不少。
table1 的记录大概有一亿条左右, 10G+.
不会存在其他 也叫 abc/xyz 的情况。
场景: boss 说把 xyz 公司的 2000 年至今的数据调出来。或者把 abc 公司的 2000 年至今的数据调出来。
直接 select * from table1 where company = 'xyz' and date between date1 and date2
是不行的。
我的想法是另外做一张表 table2 ,
id, company, all_alias
1, abc, (abc,xyz)
2, xyz, (abc,xyz)
先从 table2 中查到其所有用过的名字,
然后用 select * from table1 where company in (select all_alias from table2 where company='abc')
and date between date1 and date2
请问这样做可行否,有没有什么更好的办法?
id, company, col1,col2,...
company 里面有同一个公司发生更名情况。
比如 companyA 在 2010-01-01 以前 名字叫 abc , 2010-01-01 更名为 xyz 。
这样的公司可能有不少。
table1 的记录大概有一亿条左右, 10G+.
不会存在其他 也叫 abc/xyz 的情况。
场景: boss 说把 xyz 公司的 2000 年至今的数据调出来。或者把 abc 公司的 2000 年至今的数据调出来。
直接 select * from table1 where company = 'xyz' and date between date1 and date2
是不行的。
我的想法是另外做一张表 table2 ,
id, company, all_alias
1, abc, (abc,xyz)
2, xyz, (abc,xyz)
先从 table2 中查到其所有用过的名字,
然后用 select * from table1 where company in (select all_alias from table2 where company='abc')
and date between date1 and date2
请问这样做可行否,有没有什么更好的办法?