我有一个tbl_marksObtained
包含以下数据的表:
stdID sub marks_Obtained
201bct2007 computer 45
201bct2007 Drawing 0
202bct2007 computer 0
203bct2007 Drawing 65
.
230bct2007 computer 77
301bct2008 physics 0
301bct2008 computer 55
.
.
401bct2009 and so on..
现在我想将结果显示为:
year sub pass fail
2007 computer 20 10
2007 Drawing 15 15
2008 computer 28 2
2009 computer 20 10
我通过以下代码获得了特定年份和主题的通过失败:
SELECT
SUM( CASE WHEN marks_obtained > '0' THEN 1 END) AS pass,
SUM( CASE WHEN marks_obtained = '0' THEN 1 END) AS fail
FROM
tblstudentexammarks
WHERE
sub ='computer' AND stdID LIKE '%bce2007'
但我将如何获得上述结果的年度数据