尝试运行以下查询时,我收到错误消息“'on子句'中的未知列'YahrzeitName'”:

SELECT
concat(yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName)
AS 'YahrzeitName',

concat(yahrzeit.gregorianYear, '-', yahrzeit.gregorianMonthNum, '-', yahrzeit.gregorianDay)
AS Date,

tbldecedent.Name

FROM yahrzeit INNER JOIN tbldecedent
ON YahrzeitName = tbldecedent.Name

最佳答案

您不能在join语句中使用列别名,而是用完整的表达式替换别名:

SELECT
    concat(yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName) AS `YahrzeitName`,
    concat(yahrzeit.gregorianYear, '-', yahrzeit.gregorianMonthNum, '-', yahrzeit.gregorianDay) AS `Date`,
    tbldecedent.Name
FROM yahrzeit
INNER JOIN tbldecedent
ON concat(yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName) = tbldecedent.Name

关于mysql - 在INNER JOIN中使用列别名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43772499/

10-13 04:10