a表中有多个列
我只想要判断b列中的不重复出现的值的数量
这条sql语句要怎么写??

解决方案 »

  1.   

    select count(distinct b )from a--不重复记录
      

  2.   

    create table #1(id int)
    insert into #1 select 1
    insert into #1 select 1
    insert into #1 select 2
    insert into #1 select 2
    insert into #1 select 3
    insert into #1 select 4select count(1) from #1 t
    where exists(
    select 1 from #1 where id=t.id 
    group by id having count(1)=1
    )2
      

  3.   

    create table #1(id int)
    insert into #1 select 1
    insert into #1 select 1
    insert into #1 select 2
    insert into #1 select 2
    insert into #1 select 3
    insert into #1 select 4select count(distinct id) from #14
      

  4.   

    select count(1) from a t where (select count(1) from a where b=t.b)=1--只计算记录为1的记录