我已经成功实现了以下场景:
SELECT GROUP_CONCAT(coursecode)
FROM (
SELECT coursecode FROM Table18
WHERE regno = 'StudentXYZ' AND (ca_score + exam_score) <= 39
UNION
SELECT coursecode FROM Table17
WHERE regno = 'StudentXYZ' AND (ca_score + exam_score) <= 39
) s
WHERE coursecode
NOT IN (
SELECT coursecode
FROM Table18
WHERE regno = 'StudentXYZ'
AND (ca_score + exam_score) >= 40
UNION
SELECT coursecode
FROM Table17
WHERE regno = 'StudentXYZ'
AND (ca_score + exam_score) >= 40
)
这很好用!下面是示例结果:
+----------------------------------------------------------------------------------------------------------+
| GROUP_CONCAT(coursecode) |
+----------------------------------------------------------------------------------------------------------+
| EDU222,EDU497,POS302,POS405,POS420,EDU224,EDU311,EDU312,EDU313,GST304,GST305,POS304,POS305,POS308,POS309 |
+----------------------------------------------------------------------------------------------------------+
但这就是我想要实现的目标:
+-------------------------------------------------+
| GROUP_CONCAT(coursecode) |
+-------------------------------------------------+
| EDU222, EDU497, POS302, POS405, POS420, EDU224, |
| EDU311, EDU312, EDU313, GST304, GST305, POS304, |
| POS305, POS308, POS309 |
+-------------------------------------------------+
有什么建议么?或者更好的方法来解决这个挑战?