我这里有一张表pa(id,stuid,stuName,sex,address),我如何用sql语句求女生的人数

解决方案 »

  1.   


    select count(distinct stuid)
    from tb
    where sex = '女'
      

  2.   

    select count(1) from tb where sex='女'
      

  3.   


    select sum(case when sex='女' then 1 else 0 end) [女生人数],
           sum(case when sex='男' then 1 else 0 end) [男生人数]
    from tb
      

  4.   

    select count(*) from tb where sex ='女'
      

  5.   

    select sum(case sex when '女' then 1 else 0 end) [女生人数] from tb
      

  6.   

    select count(distinct stuid) from PA  where sex = '女'
    排除了重复的数据