Knex 查询错误 undefined column using nested select with orderBy

Knex query error undefined column using nested select with orderBy

在 Knex 查询中,我得到一个列未定义,我不知道如何解决

我在 Knex 中的查询

this.builder.orderBy(
    this.tx(messageTable)
      .max(messageColumns.createdAt)
      .where(messageColumns.conversationId, 'conversation.id')
, direction)

未定义发生在 .where(messageColumns.conversationId, 'conversation.id')

的最后一部分

我想让它与 Knex 一起工作的SQL如下

SELECT
    *
FROM
    "conversation"
ORDER BY
    (
        SELECT
            max("created_at")
        FROM
            "message"
        WHERE
            "conversation_id" = conversation.id)
    DESC

查询错误,尝试这样做:

select c.* from conversation c
join (
    select conversation_id, max("created_at") created_at
    from message
    group by conversation_id
) m on c.conversation_id = m.conversation_id
order by m.created_at DESC