主キーがあれば、これははるかに簡単です:
CREATE TABLE Purchasing (
purchasing_id int auto_increment primary key,
campaign VARCHAR(255),
main_event VARCHAR(255),
sub_event VARCHAR(255),
quantity VARCHAR(255)
);
その簡単な追加で:
SELECT p.*
FROM Purchasing p
WHERE p.purchasing_id = (SELECT p2.purchasing_id
FROM Purchasing p2
WHERE p2.campaign = p.campaign
ORDER BY field(p2.main_event, 'Storing', 'Ordered', 'Offered'),
field(p2.sub_event, 'Completed', 'Recorded', 'Delivered')
LIMIT 1
);
こちら db<>フィドルです。