表1
  a   b   c 列名
  1   2   t
  2   3   t
  4   3   r
  4   5   r
  1   2   w
现在须要根据C列来分组 我须要返回给我的是有几个组,如上表正确结果应该为3  ,求高人指点,在线等

解决方案 »

  1.   

    select count(distinct c) from tb
      

  2.   

    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([a] int,[b] int,[c] varchar(1),[列名] sql_variant)
    insert [tb]
    select 1,2,'t',null union all
    select 2,3,'t',null union all
    select 4,3,'r',null union all
    select 4,5,'r',null union all
    select 1,2,'w',null--------------------------------查询开始------------------------------select count(distinct c) from [tb]
    /*-----------
    3(1 行受影响)*/
      

  3.   

    select 
        count(distinct c) as cnt 
    from tb