如果不记得代码,也可以通过添加类似以下内容使其更易于阅读:
-- [params]
-- topic_id :topic_id
SELECT ei.user_id,
CASE
WHEN ei.status = 0 THEN 'Going'
WHEN ei.status = 1 THEN 'Interested'
WHEN ei.status = 2 THEN 'Not going'
END AS "Going?"
FROM discourse_post_event_invitees ei
JOIN posts p ON p.id = ei.post_id
WHERE p.topic_id = :topic_id
ORDER BY ei.status