如何在单列中显示以逗号分隔的多个值?
how to display multiple values, separated by commas, at single columns?
我正在使用 mysql 来执行查询。有以下7个表。
- appointment //非原子的,例如。值 -> 1,7,3
- 性别//原子值
- module //非原子的,例如。值 -> 12,33
- 计划
- 排名
- 员工
- 学生
我尝试了 'concat'、'find_in_set' 和 'in' 功能,但无法正常工作。我如何显示多个值 @ relations 'appointment' & 'module'?
以下是我能得到的最接近的说法。如果需要更多详细信息,请告诉我,谢谢。
SELECT sta.staName
, r.rank
, sta.appointmentID
, a.appointment
, m.moduleCode
FROM staff AS sta
JOIN rank AS r
ON (sta.rankID = r.rankID)
JOIN appointment AS a
ON (sta.appointmentID = a.appointmentID)
JOIN module AS m
ON (sta.teachModuleID = m.moduleID)
WHERE sta.genderID = 1;
SELECT sta.staName, r.rank, sta.appointmentID,
group_concat(distinct a.appointment) as appointments,
group_concat(distinct m.moduleCode) as moduleCodes
FROM staff AS sta
INNER JOIN rank AS r ON sta.rankID = r.rankID
INNER JOIN appointment AS a ON find_in_set(sta.appointmentID, a.appointmentID) > 0
INNER JOIN module AS m ON find_in_set(sta.teachModuleID, m.moduleID) > 0
WHERE sta.genderID = 1
GROUP BY sta.staName, r.rank, sta.appointmentID
我正在使用 mysql 来执行查询。有以下7个表。
- appointment //非原子的,例如。值 -> 1,7,3
- 性别//原子值
- module //非原子的,例如。值 -> 12,33
- 计划
- 排名
- 员工
- 学生
我尝试了 'concat'、'find_in_set' 和 'in' 功能,但无法正常工作。我如何显示多个值 @ relations 'appointment' & 'module'?
以下是我能得到的最接近的说法。如果需要更多详细信息,请告诉我,谢谢。
SELECT sta.staName
, r.rank
, sta.appointmentID
, a.appointment
, m.moduleCode
FROM staff AS sta
JOIN rank AS r
ON (sta.rankID = r.rankID)
JOIN appointment AS a
ON (sta.appointmentID = a.appointmentID)
JOIN module AS m
ON (sta.teachModuleID = m.moduleID)
WHERE sta.genderID = 1;
SELECT sta.staName, r.rank, sta.appointmentID,
group_concat(distinct a.appointment) as appointments,
group_concat(distinct m.moduleCode) as moduleCodes
FROM staff AS sta
INNER JOIN rank AS r ON sta.rankID = r.rankID
INNER JOIN appointment AS a ON find_in_set(sta.appointmentID, a.appointmentID) > 0
INNER JOIN module AS m ON find_in_set(sta.teachModuleID, m.moduleID) > 0
WHERE sta.genderID = 1
GROUP BY sta.staName, r.rank, sta.appointmentID