【发布时间】:2022-01-15 08:37:41
【问题描述】:
我需要用 Objection.js 编写这个 mysql 查询,但我不知道如何正确编写它。
这是查询(1276 是 people 表中 id 的示例):
SELECT MAX(c1.price) AS price
FROM computers c1
WHERE c1.ownerId = 1276 AND NOT EXISTS (
SELECT c2.screenSize
FROM computers c2
WHERE c2.ownerId = 1276 AND c2.screenSize > c1.screenSize
)
我已经获取了一个人的实例,现在我想做类似的事情:
person.$relatedQuery("computers", db)
.select(db.max(db.ref("price")))
.whereNotExists(qb => qb.where(....
任何建议将不胜感激!
【问题讨论】:
-
我读过:The next example shows how easy it is to build complex queries。如果真的那么容易,为什么不做呢?
标签: mysql node.js knex.js objection.js