有T1~T6,想根据表中都有的列(pubdate)按从大到小取10条记录.说白了是从6张表中按日期取10条记录

解决方案 »

  1.   


    --1select top 10 公共字段 from t1 order by pubdate --desc  排序方式
    union --all  可以取重复
    select top 10 公共字段 from t1 order by pubdate --desc
    union --all
    ...--2
    select top 10 *
    from(
    select 公共字段 from t1 
    union --all  可以取重复
    select 公共字段 from t1 
    union --all
    ...
    ) t
    order by pubdate  --desc
      

  2.   

    select top 10 * from (select * from t1 union all select * from t2 union all select * from t3 select * from t4 union all select * from t5 union all select * from t6)t order by pubdate desc
      

  3.   

    select top 10* from t1 order by pubdate desc
    union all
    select top 10* from t2 order by pubdate desc
    ...
    select top 10* from t6 order by pubdate desc
      

  4.   


    select top 10 * from (
    select * from T1
    union all
    select * from T2
    union all
    select * from T3
    union all
    select * from T4
    union all
    select * from T5
    union all
    select * from T6
    ) a order by [日期] desc
      

  5.   

    不懂lz的意思,什么是视图?View?
      

  6.   


    select top 10 * from T1
    union all
    select * from T2
    union all
    select * from T3
    union all
    select * from T4
    union all
    select * from T5
    union all
    select * from T6
    order by pubdate
      

  7.   

    表数据多试试这样子。
    select top 10 *
    from(
    select top 10 公共字段 from t1 order by pubdate --desc
    union
    select top 10 公共字段 from t2 order by pubdate --desc
    union
    ...
    ) t
    order by pubdate  --desc
      

  8.   

    lz是来搞笑的,看下view的概念
      

  9.   

    做了个测试:
    declare @t table(pubdate datetime)--包括其他列
    insert into @t select top 10 pubdate from t1 order by pubdate desc
    insert into @t select top 10 pubdate from t2 order by pubdate desc
    insert into @t select top 10 pubdate from t3 order by pubdate desc
    insert into @t select top 10 pubdate from t4 order by pubdate desc
    insert into @t select top 10 pubdate from t5 order by pubdate desc
    insert into @t select top 10 pubdate from t6 order by pubdate desc
    select top 10 * from @t order by pubdate desc
    --上述查询,总开销62,下句开销38%
    select top 10 * from(
    select top 10 pubdate from t1 order by pubdate desc
    union all
    select top 10 pubdate from t2 order by pubdate desc
    union all
    select top 10 pubdate from t3 order by pubdate desc
    union all
    select top 10 pubdate from t4 order by pubdate desc
    union all
    select top 10 pubdate from t5 order by pubdate desc
    union all
    select top 10 pubdate from t6 order by pubdate desc
    )t order by pubdate
      

  10.   

    一般就这样了,
    select top 10* from t1 order by pubdate desc
    union all
    select top 10* from t2 order by pubdate desc
    ...
    select top 10* from t6 order by pubdate desc