我正在加入多个表,其中我希望根据以下条件将一个列值放入行中TechnicianName
:
我有 4 张桌子
easy_tbljobcard
,easy_tbltechnician
并且easy_tblproblem
easy_tbltechnicianMaster
我从存在的 地方进入
TechnicianName
第二列easy_tbltechnicianMaster
technicianId
easy_tbltechnician
我想
STUFF
在我的查询中的第 3 列 (p.ProblemReported
)
当前 SQL 语句:
SELECT j.CardID,
, (SELECT TechnicianName FROM easy_tbltechnicianMaster WHERE TechnicianID = t.technicianID) AS TechnicianName
, p.ProblemReported
FROM easy_tbljobcard AS j
JOIN easy_technician AS t ON t.CardID = j.CardID
LEFT JOIN easy_tblproblem AS p ON p.CardID = t.CardID
查询结果:
╔══════════╦══════════════════╦═══════════════════╗
║ CardID ║ TechnicianName ║ ProblemReported ║
╠══════════╬══════════════════╬═══════════════════╣
║ 1 ║ AKBAR ║ PROBLEM A ║
║ 1 ║ AKBAR ║ PROBLEM B ║
║ 1 ║ AKBAR ║ PROBLEM C ║
║ 1 ║ ASANKA ║ PROBLEM A ║
║ 1 ║ ASANKA ║ PROBLEM B ║
║ 1 ║ ASANKA ║ PROBLEM C ║
╚══════════╩══════════════════╩═══════════════════╝
上面的结果应该转换成这个:
╔══════════╦══════════════════╦═════════════════════════════════╗
║ CardID ║ TechnicianName ║ ProblemReported ║
╠══════════╬══════════════════╬═════════════════════════════════╣
║ 1 ║ AKBAR ║ PROBLEM A, PROBLEM B, PROBLEM C ║
║ 1 ║ ASANKA ║ PROBLEM A, PROBLEM B, PROBLEM C ║
╚══════════╩══════════════════╩═════════════════════════════════╝
加入多个表时如何做到这一点?