在SQL2000中查询一个表中某个字段的不同记录的条数,
语句怎么写,请教

解决方案 »

  1.   

    select count(distinct col) as col from tb
      

  2.   

    select count(distinct colname) from tb
      

  3.   

    create table T1
    (A  int,
    B varchar(5)
    )insert T1
    select 1,'a' union
    select 2,'b' union
    select 3,'c' union
    select 4,'a' union
    select 5,'b' union
    select 6,'a' select B,count(B) as 不同条数 from T1 group by B 
      

  4.   


    select col , count(*) cnt from tb group by col
      

  5.   

    --sql 2000自带库pubs查询authors的情况select state , count(*) cnt from authors group by state
    /*
    state cnt         
    ----- ----------- 
    CA    15
    IN    1
    KS    1
    MD    1
    MI    1
    OR    1
    TN    1
    UT    2(所影响的行数为 8 行)
    */select count(*) from authors
    /*            
    ----------- 
    23(所影响的行数为 1 行)
    */select count(distinct state) from authors
    /*
                
    ----------- 
    8(所影响的行数为 1 行)
    */