有三个表 table2008,table2009,table2010
其中table2008这个表存的是08年的数据,table2009这个表存的是09年的数据,table2010这个表存的是10年的数据三个表的表字段名都一样  其中有内容字段 content, 开始时间 start_time,结束时间 end_time   等等,求大家帮写条语名查找出从08年某个时间段到10年某个时间段 内容字段 content相同的数据
 

解决方案 »

  1.   

    select * from 
    (
    select * from table2008
    union all
    select * from table2009
    union all
    select * from table2010
    ) t
    where 时间段 between '时间1' and '时间2'
      

  2.   

    SELECT * FROM 
    (
    SELECT * FROM TABLE2008
    UNION ALL
    SELECT * FROM TABLE2009
    ....
    )AS T WHERE 条件或者SELECT * FROM TABLE2008 WHERE 条件
    UNION ALL
    SELECT * FROM TABLE2009 WHERE 条件
    ....
      

  3.   


    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
      

  4.   

    select * from (
    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
      

  5.   

    SELECT * FROM TABLE2008 WHERE 条件
    UNION ALL
    SELECT * FROM TABLE2009 WHERE 条件我个人认为这样会效率高点吧
      

  6.   

    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
      

  7.   

    查看我的研究:
    http://blog.csdn.net/andysun88/archive/2010/03/17/5387913.aspx
      

  8.   


    --创建一个分区视图来实现。
    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'
      

  9.   

    新建的web技术交流群,欢迎大家加入一起讨论:
    群号:29037453