表里面有一堆数据,某个字段的属性不是唯一的。比如说student表
no   sex
0     F
1     M
2     F
3     F
4     M如何通过查询语句把sex这个域的单一的数量找出来,在这个表里面是2。谢谢!

解决方案 »

  1.   

    select count(distinct sex) from student表
      

  2.   

    mysql> select * from student;
    +------+------+
    | no   | sex  |
    +------+------+
    |    0 | F    |
    |    1 | M    |
    |    2 | F    |
    |    3 | F    |
    |    4 | M    |
    +------+------+
    5 rows in set (0.00 sec)
    mysql> select count(distinct sex) from student;
    +---------------------+
    | count(distinct sex) |
    +---------------------+
    |                   2 |
    +---------------------+
    1 row in set (0.00 sec)
      

  3.   

    select count(*) from (select distinct sex from student) t