拉入另一列进行查询

时间:2013-09-21 02:06:40

标签: mysql sql

我有一个查询,我需要添加一个额外的列。我有一个死灰质的时刻,需要帮助。

按原样查询

SELECT g.groupId,g.name AS groupName,l.logId,l.name AS logName, i.itemID,
i.name AS itemName, le.userName,completed, i.optimalMin,i.optimalMax ,le.value,
u.name AS unitDescription,g.parentId
FROM logExceptions le
INNER JOIN logs l ON l.logID = le.logID
INNER JOIN groups g ON g.groupId = l.groupId
INNER JOIN items i ON le.itemId = i.itemId
INNER JOIN units u ON i.unitId = u.unitId

列名实际上是l.name,但是对于parentId。附图将显示我的意思。

1 个答案:

答案 0 :(得分:0)

解决方案 SELECT g.groupId,g.name AS groupName,l.logId,l.name AS logName,i.itemID,i.name AS itemName,le.userName,completed,i。 optimalMin,i.optimalMax,le.value,u.name AS unitDescription,g.parentId,g1.name AS parentName FROM logExceptions le INNER JOIN logs l ON l.logID = le.logID INNER JOIN groups g ON g.groupId = l .groupId INNER JOIN项目i on le.itemId = i.itemId left JOIN groups g1 ON g.parentId = g1.groupId INNER JOIN units u ON i.unitId = u.unitId