我的值数组为:
const params = [
['2022-12-10', 'aaaaa', '2022-12-01', 'xhxha', '2022-12-10'],
['2022-12-11', 'ababa', '2022-12-01', 'xhxha', '2022-12-11'],
['2022-12-12', 'acaca', '2022-12-01', 'xhxha', '2022-12-12'],
['2022-12-13', 'adada', '2022-12-01', 'xhxha', '2022-12-13'],
];
const data = await db.query(`select id, title, DATE_FORMAT(end_date,"%Y-%m-%d") as end_date ABS(DATEDIFF(?, end_date))+1 as delay from chart
where uid = ?
and date = ?
and project_uid = ?
and end_date = ?
and completed is true;
`, [params]);
我想运行此查询,但所有值都被添加到第一个?(问号)。我想将这些值设置为不同的?并获得结果。
我也不想在for循环中运行查询。我如何在这里得到结果?
1条答案
按热度按时间p8h8hvxi1#
您可以连接到参数子查询。从8.0开始,您可以使用VALUES表构造函数。或者在
params
子查询中使用SELECT .. UNION ALL