有表TB1,字段a,b,c,d,表中存在大量重复数据,现在想从表中提取部分数据插入TB2中,条件是:其重复的次数在前10名,即:提取出来的数据只有10条,并且它们在TB1中重复的次数排在所有数据重复次数的前10名.请大虾们帮我一下,先谢谢!

解决方案 »

  1.   

    INSERT TB2
    SELECT TOP 10 A,B,C,D
    FROM 
    (SELECT A,B,C,D.COUNT(1) AS CNT FROM TB1 GROUP BY A,B,C,D)T
    ORDER BY CNT DESC
      

  2.   

    insert tb2 
    select top 10   a,b,c,d from tb1 group by a,b,c,d
    order by count(*) desc
      

  3.   

    insert into
     tb2 
    select 
     top 10 *
    from
     (select a,b,c,d,count(1) as num from tb 1 group by a,b,c,d)t
    order by num desc
    where
      

  4.   

    insert into
     tb2 
    select 
     top 10 *
    from
     (select a,b,c,d,count(1) as num from tb 1 group by a,b,c,d)t
    order by num desc
      

  5.   

    select top 10 A,B,C,D
    from TB1
    group by A,B,C,D
    order by count(*) desc