Postgresql Knex查询错误使用带orderBy的嵌套选择未定义列

Postgresql Knex查询错误使用带orderBy的嵌套选择未定义列,postgresql,knex.js,Postgresql,Knex.js,在Knex查询中,我得到一个列未定义,我不知道如何解析 我在Knex提出的问题 this.builder.orderBy( this.tx(messageTable) .max(messageColumns.createdAt) .where(messageColumns.conversationId, 'conversation.id') , direction) 未定义的字符出现在的最后一部分,其中(messageColumns.conversationId

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

我在Knex提出的问题

this.builder.orderBy(
    this.tx(messageTable)
      .max(messageColumns.createdAt)
      .where(messageColumns.conversationId, 'conversation.id')
, direction)
未定义的字符出现在
的最后一部分,其中(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

这很有趣,但我需要一个在KnexJS中的示例,通过这种方式,查询会给出以下错误查询1错误:错误:从表“conversation”第12行的子句条目中丢失:conversation_id)m ON c.conversation.id=m.conversation_…@Jakub,你确定吗,我觉得这个问题还可以。所以我不得不做一个新的问题,但我有一个新问题。你能在这里给我你的意见吗