我对下一个 SQL 查询(由 sequelize ORM 生成)有问题:SELECT "Publication".*, "user"."id" AS "user.id"FROM (SELECT "Publication"."club_id" AS "clubId", "Publication"."user_id" AS "userId" FROM "publication" AS "Publication" WHERE ("Publication"."club_id" = '1')) AS "Publication" LEFT OUTER JOIN "user_account" AS "user" ON "Publication"."user_id" = "user"."id";由此产生的错误是: 我对正在发生的事情的直觉是 "Publication"."user_id" 被别名为 userId 。然后,查询被别名为 "Publication"(覆盖先前引用表的标签)。左外连接尝试将新的 Publication user_id 属性与 user.id 匹配,但无法匹配,因为现在它被称为 userId 。我是否正确理解了问题? 最佳答案 答案很简单 user_id userId :SELECT "Publication".*, "user"."id" AS "user.id"FROM (SELECT "Publication"."club_id" AS "clubId" ,"Publication"."user_id" AS "userId" FROM "publication" AS "Publication" WHERE "Publication"."club_id" = '1') AS "Publication"LEFT JOIN "user_account" AS "user" ON "Publication"."userId" = "user"."id"; -- here use column's alias关于sql - 别名后外连接中不存在列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46078579/
10-11 04:23