日期:2014-05-18  浏览次数:20580 次

求这种统计SQL语句怎么写
现在有张表 baoming,里面有kh(考号),yw(语文),sx(数学),yy(英语)等几个科目的字段,当某个学生相应科目比如语文报了名以后字段值为true,数学没报则为false,我怎么用比较简单的语句统计出各科的报名情况(就是报名人数),下面是我想像中的SQL语句,怎么加条件分别判断各科,高手帮帮忙
SQL code

select count(yw) as yw,count(sx) as sx,count(yy) as yy,count(wl) as wl,count(hx) as hx,count(zz) as zz,
    count(ls) as ls,count(sw) as sw,count(dl) as dl,count(xx) as xx 
    from baoming



------解决方案--------------------
是Bit值吧?

用sum計算

sum(yw*1)
------解决方案--------------------
SQL code
select sum(yw*1) as yw,sum(sx*1) as sx,sum(yy*1) as yy,sum(wl*1) as wl,sum(hx*1) as hx,sum(zz*1) as zz,
    sum(ls*1) as ls,sum(sw*1) as sw,sum(dl*1) as dl,sum(xx*1) as xx 
    from baoming