数据库是ACCESS的,我现在想要把表A中的数据筛选导入到表B中
表A:
列1  列2
a   123
a   456
a   468
a   568
b   654
b   987
b   756要查询,让列1中的数据,比如A,如果列2中它的数据超过10条,就导入表B
这样要如何写?

解决方案 »

  1.   


    select * into 表B from 表A where 列1 in (select 列1 from (select 列1,count(*) as num from 表A group by 列1) as A where A.num>10) as B 
      

  2.   


    declare @A table(id char(1), col int)
    declare @B table(id char(1), col int)insert into @A select 'a',  123 
    insert into @A select 'a',  456 
    insert into @A select 'a',  468 
    insert into @A select 'a',  568 
    insert into @A select 'b',  654 
    insert into @A select 'b',  987 
    insert into @A select 'b',  756 insert into @B
    select * from @A A where exists(select 1 from @A where id = A.id group by id having count(1) > 3) --这儿到时改成10
    select * from @A
    select * from @B
    ----------------------------
    id   col
    ---- -----------
    a    123
    a    456
    a    468
    a    568
    b    654
    b    987
    b    756(7 行受影响)id   col
    ---- -----------
    a    123
    a    456
    a    468
    a    568(4 行受影响)
      

  3.   

    测试通过~~insert into B(列1,列2) select 列1,列2  from A 
    where  A.列1 in 
    (SELECT A.列1
    FROM [SELECT A.列1, Count(A.列2) AS Num
    FROM A GROUP BY A.列1]. AS A 
    WHERE A.Num>10)