select count(*)
 from A aa,(select top 1 * from A)bb
 where aa.id<>bb.id
 and aa.name=bb.name
试一试。

解决方案 »

  1.   

    select count(*) from a 
    where id between (
    select min(id) from a 
    where name=(select top 1 name from a)
    and id<>(select min(id) from a)
    ) and(
    select min(id) from a 
    where name<>(select top 1 name from a)
    )
      

  2.   

    --改一下:
    select count(*) from a 
    where id between (
    select min(id) from a 
    where name=(select top 1 name from a)
    and id<>(select min(id) from a)
    ) and(
    select min(id) from a 
    where name<>(select top 1 name from a)
    )-1
      

  3.   

    --测试--测试数据
    create table A(id int,name varchar(10))
    insert A  select 1,'tom'
    union all select 2,'tom'
    union all select 3,'tom'
    union all select 4,'peter'
    union all select 5,'tom'
    goselect count(*) from a 
    where id between (
    select min(id) from a 
    where name=(select top 1 name from a)
    and id<>(select min(id) from a)
    ) and(
    select min(id) from a 
    where name<>(select top 1 name from a)
    )-1
    go--删除测试
    drop table a/*--测试结果
    ----------- 
    2(所影响的行数为 1 行)--*/
      

  4.   

    多谢zjcxc(: 邹建 :) 怎么到处都可以看到你的身影
    像个救火队员!能介绍下你自己么?