javascript - Knex 从多个表中选择

标签 javascript node.js postgresql knex.js bookshelf.js

我想用 knex 运行以下 SQL:

select * from (
  (select * from foo)
  union all
  (select * from bar)) as biz limit 10 offset 20;

有没有不用 knex.raw 的方法?

最佳答案

knex 确实支持 unionunionAll。它被记录在案

knex.select().from(function() {
    this.select().from('foo')
        .unionAll(function() {
            this.select().from('bar')
        }).as('biz')
}).limit(10).offset(20).toString()

输出:

select * from (select * from `foo` union all select * from `bar`) as `biz` limit 10 offset 20

关于javascript - Knex 从多个表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44929051/

相关文章:

javascript - 获取在 Javascript 中提交后显示的 SPARQL 查询

javascript - 如何使用 nextProps 值在 React componentWillReceiveProps 方法中编写整洁干净的代码

javascript - 延迟循环nodejs的每次迭代

postgresql - 如何解释 PostgreSQL txid_current() 值

javascript - 输入字段显示 NaN

javascript - 如何读取 Firebase Cloud Functions 的 index.js 中的 Firebase 数据库条目?

java - 如何在 Java Servlet 中从多个表 (PostgreSQL) 检索数据?

ruby-on-rails - 整数、索引列、外键、引用之间的差异和最佳实践

node.js - 使用 Node.js 通过 MQTT 连接到 Google Cloud IoT 时遇到问题

javascript - Angular 选择不填充选项