条件如下  :  
 
有一表A,有字段a  
 
a  列中有多个重复的数据  
 
有没有一条语句求出不包括重复数据的行数?

解决方案 »

  1.   

    --这样?
    declare @t table(a int,b int)
    insert into @t select 1,2
    insert into @t select 1,3
    insert into @t select 1,1
    insert into @t select 2,4
    insert into @t select 1,2
    insert into @t select 3,2select count(1) from (select a from @t group by a having count(*)=1)t
      

  2.   

    select sum(1) from Ta TT
    where not exists (select 1 from Ta where a=TT.a)
      

  3.   

    --这样?
    declare @t table(a int,b int)
    insert into @t select 1,2
    insert into @t select 1,3
    insert into @t select 1,1
    insert into @t select 2,4
    insert into @t select 1,2
    insert into @t select 3,2select count(1) from (select a from @t group by a having count(*)=1)t
      

  4.   

    --测试环境
    create table mytab
    (
    id int,
    a varchar(10)
    )
    insert into mytab select 1,'a'
    insert into mytab select 2,'b'
    insert into mytab select 3,'b'
    insert into mytab select 4,'c'
    insert into mytab select 5,'d'
    insert into mytab select 6,'d'--查询所有不重复的a,结果为4
    select count(1) from (select distinct a from mytab)a
    --查询没有重复行的a,结果为2
    select count(1) from (select a from mytab group by a having count(1) < 2)a
      

  5.   

    select sum(1) from Ta TT
    where not exists (select 1 from Ta where a=TT.a)
    ---->更正select sum(1) from
    (
    select a from @t 
    group by a
    having count(*)=1
    ) t
      

  6.   

    xeqtr1982(vesslan)的数据
    select * from @t group by a,b having count(*)=1
      

  7.   

    表数据如下:id,a
    1,'a'
    2,'a'
    3,'b'
    4,'b'
    5,'c'计算结果:
    行数:3一条sql语句可以做到吗?
      

  8.   

    declare @t table(id int,a varchar(10))
    insert into @t select 1,'a'
    union all select 2,'a'
    union all select 3,'b'
    union all select 4,'b'
    union all select 5,'c'select count(*) from (select a from @t group by a)t
      

  9.   

    coolingpipe(冷箫轻笛)厉害.谢谢,
    我要的就是这个一种,select count(1) from (select distinct a from mytab)a
      

  10.   

    同样谢谢,xeqtr1982(vesslan)及大家,结贴了
      

  11.   

    select count(*) 
    from t
    group by a不可以吗