我想用 knex 运行以下 SQL:
select * from (
(select * from foo)
union all
(select * from bar)) as biz limit 10 offset 20;
有没有不用 knex.raw
的方法?
最佳答案
knex 确实支持 union
和 unionAll
。它被记录在案
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/