我正在尝试在 typeorm 中构建以下查询。
SELECT * from Department where
type = 'Employee' and
((from_date BETWEEN '2013-01-03'AND '2013-01-09') OR
(to_date BETWEEN '2013-01-03' AND '2013-01-09') OR
(from_date <= '2013-01-03' AND to_date >= '2013-01-09'))
下面是我的 typeorm 等价物。
connection.find(Department, {
where: [
{ fromDate: Between(filter.fromDate, filter.toDate) },
{ toDate: Between(filter.fromDate, filter.toDate) },
{
fromDate: LessThanOrEqual(filter.fromDate),
toDate: MoreThanOrEqual(filter.toDate),
},
],
andWhere: { type: 'Employee' },
});
但不知何故我得到了错误的输出数量。好像 andWhere 不起作用。 提前致谢
最佳答案
let qb = this.repository.createQueryBuilder("department");
qb.where("department.type= :type", {type: "Employee"});
qb.andWhere("((department.from_date BETWEEN '2013-01-03'AND '2013-01-09') OR
(department.to_date BETWEEN '2013-01-03' AND '2013-01-09') OR
(department.from_date <= '2013-01-03' AND department.to_date >= '2013-01-09'))");
关于javascript - Typeor find with and & or where block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62004119/