我已经从下面的记录中创建了一个临时表。我想用学生id(stu\d)对学生分组。分组时,如果他通过了所有科目,则学生成绩状态为通过;如果他至少一个科目不通过,则学生成绩状态为不通过。提前谢谢
h6my8fg21#
尝试此查询
SELECT stu_Name,result FROM `marks` WHERE stu_D not in (SELECT stu_D FROM marks WHERE result='FAILED') GROUP BY stu_D
zvms9eto2#
SELECT T.stu_D, T.stuName, IF(T.number_of_failures>0, 'FAILED', 'PASSED') final_result FROM (SELECT stu_D, stuName, COUNT(IF(result='FAILED', 1, NULL)) number_of_failures FROM your_table GROUP BY stu_D, stuName) T;
ipakzgxi3#
你可以试试下面的查询-
SELECT stu_D ,stuName ,CASE WHEN T2.CNT = 0 THEN 'passed' ELSE 'failed' END status FROM (SELECT stu_D ,stuName ,COUNT(CASE WHEN result = 'FAILED' THEN 1 END) CNT FROM T GROUP BY stu_D ,stuname) T2
3条答案
按热度按时间h6my8fg21#
尝试此查询
zvms9eto2#
ipakzgxi3#
你可以试试下面的查询-