mysql - Filter students that have not passed a subject yet -


i have mysql table , has following values:

table name 'results'

reg.no  subjectcode  attempt  pass/fail 112108  cmis 1113    1        fail 112110  cmis 1114    1        pass 112119  cmis 1114    1        fail 112108  cmis 1113    2        fail 112107  cmis 1113    1        fail 112108  cmis 1113    3        pass 

students can have several attempts pass subject. student should pass each subjects degree. student pass in first attempt. take more 3 attempt. student can try until he/she pass. still remain fail. want reg.no of students still unable pass subject.
eg.: 112119 , 112107 still unable pass subject.
unable write query problem.

i suggest using aggregation:

select `reg.no`, subjectcode, sum(`pass/fail` = 'pass') results group  `reg.no`, subjectcode having sum(`pass/fail` = 'pass') = 0; 

the having clause counts number of results each student , course last column 'pass'. in mysql, booleans treated integers in numeric context, true being 1. so, sum(pass/fail= 'pass') counts number of times student passed course. = 0 says student never passed course.

as suggestion, don't put special characters such / , . in column names. requires escaping columns , makes code harder write because filled backticks.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -