有三个表 table2008,table2009,table2010
其中table2008这个表存的是08年的数据,table2009这个表存的是09年的数据,table2010这个表存的是10年的数据三个表的表字段名都一样 其中有内容字段 content, 开始时间 start_time,结束时间 end_time 等等,求大家帮写条语名查找出从08年某个时间段到10年某个时间段 内容字段 content相同的数据
其中table2008这个表存的是08年的数据,table2009这个表存的是09年的数据,table2010这个表存的是10年的数据三个表的表字段名都一样 其中有内容字段 content, 开始时间 start_time,结束时间 end_time 等等,求大家帮写条语名查找出从08年某个时间段到10年某个时间段 内容字段 content相同的数据
(
select * from table2008
union all
select * from table2009
union all
select * from table2010
) t
where 时间段 between '时间1' and '时间2'
(
SELECT * FROM TABLE2008
UNION ALL
SELECT * FROM TABLE2009
....
)AS T WHERE 条件或者SELECT * FROM TABLE2008 WHERE 条件
UNION ALL
SELECT * FROM TABLE2009 WHERE 条件
....
select content count(content) from
(
select * from table2008
unill all
select * from table2009
unill all
select * from table2010
)
awhere start_time>='2009-10-10' and end_time<='2009-12-10'
group by content having count(content)>1
select *,counT(*) over(partition by content) as cnt from
(select * from table2008
union all
select * from table2009
union all
select * from table2010
) a
where 08年某个时间<start_time and end_time<10年某个时间段
) where cnt>1
UNION ALL
SELECT * FROM TABLE2009 WHERE 条件我个人认为这样会效率高点吧
(
select * from table2008
unill all
select * from table2009
unill all
select * from table2010
)
awhere start_time>='2009-10-10' and end_time<='2009-12-10'
group by content having count(content)>1
http://blog.csdn.net/andysun88/archive/2010/03/17/5387913.aspx
--创建一个分区视图来实现。
CREATE VIEW v_table
AS
BEGIN
SELECT * FROM table2008
UNION ALL
SELECT * FROM table2009
UNION ALL
SELECT * FROM table2010
END SELECT * FROM v_table WHERE 时间段 between '时间1' and '时间2'
群号:29037453