我想用knex运行以下SQL:
select * from (
(select * from foo)
union all
(select * from bar)) as biz limit 10 offset 20;
有没有办法在没有knex.raw
的情况下执行此操作?
答案 0 :(得分:3)
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