SELECT specID1, specID1 AS specID2
FROM Table1
GROUP BY specID1可以吗,你说的不是很清楚

解决方案 »

  1.   

    select SELECT specID1, count(*) AS specID2
    FROM Table1
    GROUP BY specID1
      

  2.   

    我希望是这个意思:SELECT count(*), count(specID1 = specID2)
    FROM Table1
    GROUP BY specID1可是不行!!
      

  3.   

    既然是specID2 等于specID1的数量select specID1,specID2=max(specID1) from tb
    where specID1=specID2
    group by specID1可是這樣寫好象覺得沒有意思﹖請樓再說明清楚一點﹖﹖
      

  4.   

    select specID1,specID2=count(specID2) from 表 group by specID1
      

  5.   

    你希望是这样:
    ID   con
    1    a
    1    bID  ID1
    1    2
    如果是这样,用我上面的语句就可以了
      

  6.   

    這樣寫吧SELECT specID1, num=count(specID1)
    FROM Table1
    where specID1=specID2
    GROUP BY specID1
      

  7.   

    --建表:create table A(a int,b int)
    select a.*,b.bnum from 
        (select a,count(a) as anum from a group by a) a,
        (select b,count(b) as bnum from a group by b) b 
             where a.a=b.b
      

  8.   

    create table ta(id int ,num numeric(10))
    Insert into ta
    select 1,2
    union all select 1,2
    union all select 1,null
    union all select 2,3
    union all select 3,1
    union all select 3,1select * from ta--刪除
    drop table taselect id,id_num=count(id),num=count(num) from ta group by id
    --結果
    id      id_num   num
    -------------------
    1 3 2
    2 1 1
    3 2 2
      

  9.   

    原表:
    e   f
    1   2
    1   2
    1
    2   3
    3   1
    3   1
    结果:
    a   b                 c
    1  3个(e列中有3个1)  2个(f列中有2个1)
    2  1个(e列中有1个2)  2个(f列中有2个2)
    3  2个(e列中有2个3)  1个(f列中有1个3)
    生成的b列是e列中的个数,生成的c列是f列中等于e列的个数
      

  10.   

    用: hdhai9451(※★開拓者.....☆※) ( ) 信誉:100 
    的方法可以了,我写得差了
      

  11.   

    select a=a.id,b=a.num,c=(select count(num) from ta b where b.num=a.id) 
    from
    (select id,num=count(id) from ta group by id)a
    --結果
    a        b         c
    -----------------------------
    1 3 2
    2 1 2
    3 2 1
      

  12.   

    是这样吧:
      select specID1, count(specID1),count(*)
    FROM Table1
    WHERE specID1=specID2
    GROUP BY specID1
      

  13.   

    谢谢大家的帮助
    可是结果不符合我的要求呀,请看青我的问题呀:
    原表:
    e   f
    1   2
    1   2
    1
    2   3
    3   1
    3   1
    结果:
    a   b                 c
    1  3个(e列中有3个1)  2个(f列中有2个1)
    2  1个(e列中有1个2)  2个(f列中有2个2)
    3  2个(e列中有2个3)  1个(f列中有1个3)
    生成的b列是e列中的个数,生成的c列是f列中等于e列的个数
      

  14.   

    带测试数据及结果:create table AA (SpecID1 Int ,AName varchar(20) ,SpecID2 Int)Insert Into AA Values(1,'a', 2)
    Insert Into AA Values(1,'b', 2)
    Insert Into AA Values(1,'c', null)
    Insert Into AA Values(2,'d', 3)
    Insert Into AA Values(3,'e', 1)
    Insert Into AA Values(3,'f', 1)Select B.Specid1,B.N1,C.N2 from 
    (Select SpecID1,Count(Specid1) as N1 from AA where specid1 is not null Group by SpecID1) B,
    (Select SpecID2,Count(Specid2) as N2 from AA where specid2 is not null Group by SpecID2 ) C where (B.SpecID1=C.SpecID2)
      

  15.   

    结果:
    SPECID1  N1       N2
    1 3 2
    2 1 2
    3 2 1
      

  16.   

    create table ta(id int ,num numeric(10))
    Insert into ta
    select 1,2
    union all select 1,2
    union all select 1,null
    union all select 2,3
    union all select 3,1
    union all select 3,1select * from ta
    select id,id_num=count(id),num=(select count(1) from ta where num=a.id) from ta a group by id
    drop table ta
      

  17.   

    mastersky(浪)
    我和这位兄弟一样,其它的方法也有就是不爽了
      

  18.   

    试试下面:
    select specid1,count(*),(select count(*) from 表名 as t1 group by specid2 having t1.specid2=t2.specid1) from 表名 as t2 group by specid1 
    没测试的