例子:
     ID号              状 态
     01                优
     01                良
     01                中
     02                良
     03                中
     03                良
想得到的结果:
   
      ID号的个数为3个我用的是sql server 2000 
请问应该怎么写啊 谢谢

解决方案 »

  1.   

    Select Count(Distinct ID号 ) As 个数 From 表
      

  2.   

    select count(distinct ID号 ) from 表 group by (distinct  ID号 )
      

  3.   

    select count(distinct ID号) from 表
      

  4.   

    select 'ID号的个数为'+rtrim(count(*))+'个' from 表 group by ID号
      

  5.   

    --創建測試環境
    Declare @T Table(ID号 Char(2), 状态 Nvarchar(10))
    Insert @T Select     '01',                N'优'
    Union All Select      '01',                N'良'
    Union All Select      '01',                N'中'
    Union All Select      '02',                N'良'
    Union All Select      '03',                N'中'
    Union All Select      '03',                N'良'
    --測試
    Select Count(Distinct ID号 ) As 个数 From @T
    --結果
    /*
    个数
    3
    */
      

  6.   

    select count(distinct id) from t