如果数据足够相似,可以一起查询,那么它可能足够相似,可以一起存储在一个表中,并带有一个额外的列来记录类型,但是......
select * from (
select 'table1', timestamp_col, fName, lName, scorePercent, numCorrect
from table1 where ...
UNION ALL
select 'table2', timestamp_col, fName, lName, scorePercent, numCorrect
from table2 where ...
UNION ALL
select 'table3', timestamp_col, fName, lName, scorePercent, numCorrect
from table3 where ...
UNION ALL
select 'table4', timestamp_col, fName, lName, scorePercent, numCorrect
from table4 where ...
UNION ALL
select 'table5', timestamp_col, fName, lName, scorePercent, numCorrect
from table5 where ..
) x
order by timestamp_col desc
您可以在内部查询之外使用单个 where 语句,但它的性能会很差,因为所有表的所有行都将合并。这样,只有实际需要的行被联合起来。
请注意,这UNION ALL
是一个比 , 更好的选择UNION
,因为UNION ALL
不排序(UNION
数据将被排序两次- 一次用于删除重复项,再次用于排序)。