編集済み
これを試して:
SELECT * FROM complaints
WHERE NOT EXISTS
(SELECT complaintid
FROM tasks
WHERE complaintid
in (SELECT complaintID
FROM tasks
WHERE tasks.complaintID = complaints.complaintid
and completed = 'no')
)ORDER BY deadline;
SQL フィドルのデモ
これは、上記の私の回答をテストするために使用した場合のテーブル構造とサンプル データです。
CREATE TABLE complaints (
complaintID INT AUTO_INCREMENT PRIMARY KEY,
content VARCHAR(255),
deadline datetime
);
CREATE TABLE tasks (
tasksid INT AUTO_INCREMENT PRIMARY KEY,
complaintID INT,
completed ENUM ('yes','no')
);
INSERT INTO complaints(content,deadline) VALUES ('complaint1', NOW()+INTERVAL 3 day), ('complaint2',NOW()+INTERVAL 8 day),('complaint3', NOW()+INTERVAL 3 day);
INSERT INTO tasks (complaintID, completed) VALUES(1,'no'), (1,'yes'), (2,'yes'), (1,'no'), (1,'yes'), (1,'yes'), (2,'no'), (3,'yes'), (3, 'yes');