select count(distinct name) from table;

解决方案 »

  1.   

    select count(*) from 
    (
    select distinct name,sex form table
    ) as a
      

  2.   

    select count(*) from (select distinct name,sex form table) as a
      

  3.   

    select count(*) from 
    ( select distinct name,sex form table
    ) as table1
     
      

  4.   

    select distinct name,sex form table
    select @@ROWCOUNT 
    @@ROWCOUNT 是系统变量,返回受上一语句影响的行数。
    下面的示例执行 UPDATE 语句并用 @@ROWCOUNT 来检测是否有发生更改的行。
    UPDATE authors SET au_lname = 'Jones'
    WHERE au_id = '999-888-7777'
    IF @@ROWCOUNT = 0
       print 'Warning: No rows were updated'