I currently have the following query, which is intended to give me a single row in a report that will contain one of three string values ('Yes', 'No', 'Missed'). 'Yes'/'Missed' are currently functioning as intended, but for the life of me I cannot figure out why 'No' is not working. Is this because of the joined queries which both use GROUP BY?
The only way I know of being able to determine if 'No' should be present in a given row is when rvm_mark.review_object is LEFT JOIN to rvm_review_object.id (rvm_review_object is an upper level table). There are several instances where rvm_review_object.id would not have a matching rvm_mark.review_object and that should be where a 'No' would be used.
What am I doing wrong and or missing?
This is a continuation of my currently unanswered question located here: Condensed CASE across multiple tables with conditions
Information regarding the relationships between the tables can be located there along with sample data as CSV for anyone wanting to test their queries.
SELECT rvm_review_object.dse_object_id, rvm_review_object.id,
T_Mark.creator, T_Mark.review_object,
IF(T_Mark.Comment IS NULL, 'No', T_Mark.Comment) AS Comment
FROM rvm_review_object
LEFT JOIN(
SELECT rvm_mark.review_object, rvm_mark.creator, rvm_mark.id,
CASE WHEN MAX(T_Comment.Comment = 'Yes') = 1 THEN 'Yes'
ELSE 'Missed'
END AS Comment
FROM rvm_mark
LEFT JOIN(
SELECT rvm_comment.mark,
CASE WHEN MAX((rvm_comment.note IS NULL OR rvm_comment.note = '')
AND rvm_comment.deleted = FALSE) = 1
THEN 'Missed'
ELSE 'Yes'
END AS Comment
FROM rvm_comment
GROUP BY rvm_comment.mark) AS T_Comment
ON T_Comment.mark = rvm_mark.id
WHERE rvm_mark.deleted = FALSE
GROUP BY rvm_mark.review_object) AS T_Mark
ON T_Mark.review_object = rvm_review_object.id
WHERE rvm_review_object.creator != T_Mark.creator
Aucun commentaire:
Enregistrer un commentaire