select jieciid,projectid,
        voteresult1=sum(case when voteresult=1 then 1 else 0 end),
        voteresult2=sum(case when voteresult=2 then 1 else 0 end),
        voteresult3=sum(case when voteresult=3 then 1 else 0 end),
        voteresult4=sum(case when voteresult=4 then 1 else 0 end) from t_voteresult group by jieciid,projectid

解决方案 »

  1.   

    CREATE VIEW YourView AS
    SELECT projectid AS 项目编号,
           jieciid AS 评审届次,
           voteresult1=sum(case when voteresult=1 then 1 else 0 end),
            voteresult2=sum(case when voteresult=2 then 1 else 0 end),
            voteresult3=sum(case when voteresult=3 then 1 else 0 end),
            voteresult4=sum(case when voteresult=4 then 1 else 0 end) from t_voteresult group by jieciid,projectid