我正在用 knex.js 编写查询,但我被 orWhere 卡住了。
我需要这样的查询:
select
count(*)
from
`Project`
where
`Project`.`createdAt` >= '2019-11-12'
and
`Project`.`createdAt` <= '2020-11-19'
and
((`Project`.`productType` = 1)
or
(`Project`.`productType` = 2))
但由于某种原因,这就是我得到的:
select
count(*)
from
`Project`
where
`Project`.`createdAt` >= '2019-11-12'
and
`Project`.`createdAt` <= '2020-11-19'
or
(`Project`.`productType` = 1)
or
(`Project`.`productType` = 2)
or
请注意,我想要两个 'and
来代替第一个or
这是代码:
builder.count('*')
.from('Project')
.where('Project.createdAt', '>=', '2019-11-12')
.where('Project.createdAt', '<=', '2019-11-19')
.orWhere({'Project.productType': 1})
.orWhere({'Project.productType': 2})
将不胜感激任何帮助