表Aa b
1 w
2 q
3 n
4 e
....如何随机提取表A中的N条数据(比如1000条),并且数据不能重复

解决方案 »

  1.   

    SELECT TOP 1000 *
    FROM tb
    ORDER BY NEWID()
      

  2.   


    SQL codeSELECT TOP 1000 *
    FROM tb
    ORDER BY NEWID()
    [/Quote]
      

  3.   


    select top 1000 distinct * from tb ORDER BY NEWID()
      

  4.   

    select top 1000 distinct * from tb ORDER BY NEWID()
      

  5.   

    select top 1000 distinct * from tb ORDER BY NEWID()
      

  6.   

    select top 1000 distinct * from tb ORDER BY NEWID()
      

  7.   

    表A a b 
    1 w 
    2 q 
    3 n 
    4 e 
    .... 如何随机提取表A中的N条数据(比如1000条),并且数据不能重复并且生成1个这N个数据的新表 TB1? 
      

  8.   

    select top 1000 distinct * into TB1 from tb ORDER BY NEWID() --TB1事先不存在
    insert TB1 select top 1000 distinct *  from tb ORDER BY NEWID() --TB1事先存在.且结构与tb匹配
      

  9.   

    谢谢您的回复,为什么加入distinct去掉重复值就提示有语法错误,去掉distinct就可以那?
      

  10.   


    select top 1000 * from (select distinct * from tb) t ORDER BY NEWID() select top 1000 * into tb1 from (select distinct * from tb) t ORDER BY NEWID()