模拟考试的试卷,一般分几个部分,如第一部分选择题;第二部分问答题等,
但各个试卷不一样,有的有3部分,有的只有1部分。
现要统计各个试卷做了多少部分:试卷 部分 做否shj1 1 Yes
shj1 2 No
shj1 3 Yes
shj2 1 Yes
shj3 1 No
shj3 2 No
要求结果为:试卷 未做部分
shj1 1
shj2 0 <----尤其是这条,一定要有
shj3 2

解决方案 »

  1.   

    select 试卷 count(做否) as 未做部分  form tablename where 做否 = 'no' group by 试卷
      

  2.   

    ALTER  TABLE tablename add  isYn INT 
    update tablenameset isYN=0
    update tablename set isYN=1 where c='No'
    select 试卷,sum(isYn) as 未做部分 from tablename group by 试卷
    ALTER TABLE tablename drop isYn
      

  3.   

    to maimaizhi(mutiny) :你的做法可以,和我的差不多。但不知还有无更好的办法?
    我的做法:
    (select 试卷,0 as isYn from tblname group by 试卷) as v1
    (select 试卷,count(部分) as isYn from tblname where c='No' group by 试卷) as v2select 试卷,sum(isYn) from
    v1 UNION v2
    group by 试卷
      

  4.   

    select t1.试卷,sum(t1.isYn) 
    from (select 试卷,isYn=case 做否 when 'Yes' then 0 else 1 end from tablename) as t1 group by t1.试卷