select count(distinct code) from table WHERE type='a'

解决方案 »

  1.   

    OR:
    select COUNT(distinct CASE WHEN type='a' THEN code ELSE NULL END) AS ACNT,
    COUNT(distinct CASE WHEN type='b' THEN code ELSE NULL END) AS BCNT
    from table
      

  2.   

    因為還有其他查詢條件,不能用 from table where type='a',隻能在前面用
      

  3.   

    select Distinct Count(code) from table WHERE type='a'
      

  4.   

    select count(distinct code) from [table] WHERE type='a'
      

  5.   

    select Distinct Count(case when type='a' then code else null end) from table 
      

  6.   

    更正:
    select  Count( Distinct case when type='a' then code else null end) 
    from table