下面显示的我当前的查询显示了用户详细信息及其注册的事件,但是在他们参加活动后,我想要另一列显示WHERE Start_Date 理想情况:SELECT users.username, users.user_firstname, users.user_lastname, users.user_role,
GROUP_CONCAT( Events.Event_Name ) AS Event_Names, COUNT(Events.Event_Name) AS Event_Count
FROM users LEFT JOIN
user_events
ON users.id = user_events.id LEFT JOIN
Events
ON Events.Event_ID = user_events.Event_ID
GROUP BY users.username, users.user_firstname, users.user_lastname, users.user_role
| username| user_firstname | user_lastname | user_role | Event_Name |PreEve
| M | jo | mccann | employee | baking,run | fight
答案 0 :(得分:0)
这是您想要的吗?
SELECT u.username, u.user_firstname, u.user_lastname, u.user_role,
GROUP_CONCAT(CASE WHEN e.Start_Date < CURDATE() THEN e.Event_Name END) AS Previous_Event_Names,
GROUP_CONCAT(CASE WHEN e.Start_Date >= CURDATE() THEN e.Event_Name END) AS Future_Event_Names,
COUNT(e.Event_Name) AS Event_Count
FROM users u LEFT JOIN
user_events ue
ON u.id = ue.id LEFT JOIN
Events e
ON e.Event_ID = ue.Event_ID
GROUP BY u.username, u.user_firstname, u.user_lastname, u.user_role;
GROUP_CONCAT()
忽略了NULL
值。