SQL数据库中Case End语句应用总结

来源:互联网 发布:2017年猝死的程序员 编辑:程序博客网 时间:2024/06/04 18:09

   Select  PR_PT.cTmpCode,max(PR_PT.cTmpName) as cTmpName,max(PR_PT.cDescription) as cDescription,case when exists(select * from              PR_StuPrintRecord           S   where S.cTmpCode = PR_PT.cTmpCode and S.cStuCode='20122015') then (select count(*) from   PR_StuPrintRecord SPR where SPR.cTmpCode= PR_PT.cTmpCode and SPR.cStuCode='20122015' )  else 0 end as iPrintTimes,max(iPrintLimitTimes) as iLimitTimes  From PR_PrintTemplate  PR_PT  group by PR_PT.cTmpCode order by PR_PT.cTmpCode  根据学号对不同的打印模块进行打印次数统计,如果该学号的某打印模块尚未打印显示为0,否则显示

相应的打印次数。