我正在尝试从要使用多个条件的表中过滤数据。当我在查询中应用它显示应用程序错误。 怎么做?
我正在使用nodejs框架,express,sequelize和mysql。
router.get('/booking-information', function (req, res) {
// Get orders
Promise.all([Order.findAll({
/*where: {
endDate: null,
},*/
order: [
['id', 'DESC'],
]
}),
Professional.findAll({where: {status : '1'}})
])
.then(([orders, professionals]) => {
orders.map((order) => {
let professionalsInSameArea = professionals.filter((professional) => {
return (professional.service === order.service || professional.secondary_service LIKE '%' + order.service + '%') && (professional.area === order.area || order.area === professional.secondary_area);
});
order.professionals = [...professionalsInSameArea]
return order;
});
res.render('booking-information', {title: 'Technician', orders: orders, user: req.user});
})
.catch((err) => {
console.error(err);
});
});
我想筛选出订单所在领域和服务相同的专业人员。
答案 0 :(得分:0)
you can use Op operator in query
like :-
const Op = Sequelize.Op
{
[Op.or]: [
{
fieldName: {
[Op.like]: 'abc%'
}
},
{
fieldName: {
[Op.like]: '%abc%'
}
}
]
}
答案 1 :(得分:0)
信不信由你,您只能使用String.indexOf
函数,因为
根据定义,SET @cumulative := 0;
SELECT
YEAR(log_at) as year,
MONTH(log_at) as month,
DAY(log_at) as day,
SUM(ev) as dailyTotal,
@cumulative := @cumulative + sum(ev) AS cumulative,
count(*) as count
FROM tracks
WHERE user_id = 1
GROUP BY year, month, day
ORDER BY year, month, day ASC
表示String LIKE %word%
包含 String
:
word