mysql - 如何在 node.js 中减去 knex.raw 中的查询
问题描述
我已经在 mysql 中完成了这个查询,但我不知道如何在 knex.raw 中执行此操作。
select ((select leave_trackers.available_leaves from leave_trackers) -
(SELECT ((DATEDIFF('2018-06-11', '2018-06-01') + 1) -
(WEEK('2018-06-11') - WEEK('2018-06-01')) -
(case when weekday('2018-06-11') = 6 then 1 else 0 end) -
(SELECT IFNULL(sum(total), 0)
from
(
select count(holidays.date) as total
FROM holidays, leave_applications
WHERE holidays.date between '2018-06-01' and '2018-06-01'
GROUP BY holiday_id) as holiday_leave
)
) as available_leaves
FROM leaves
group by leave_id
));
有人可以帮我把它转换成 knex.raw 吗?
解决方案
knex.raw(`
select ((select leave_trackers.available_leaves from leave_trackers) -
(SELECT ((DATEDIFF('2018-06-11', '2018-06-01') + 1) -
(WEEK('2018-06-11') - WEEK('2018-06-01')) -
(case when weekday('2018-06-11') = 6 then 1 else 0 end) -
(SELECT IFNULL(sum(total), 0)
from
(
select count(holidays.date) as total
FROM holidays, leave_applications
WHERE holidays.date between '2018-06-01' and '2018-06-01'
GROUP BY holiday_id) as holiday_leave
)
) as available_leaves
FROM leaves
group by leave_id
))
`).then(res => console.log(res));
If that doesn't work we need more info about what is going wrong.
推荐阅读
- javascript - 在javascript中的正确时间拆分文本
- python-3.x - Python Min Max While 循环
- android - java.lang.IllegalArgumentExceptionIllegalArgumentException:索引 2 处的绑定值为 null
- php - Laravel 验证只允许某些字符
- r - 从 R 中的 INLA.surv 模型中提取努力成功关系
- c# - 使用数据库中的openxml生成excel表
- typescript - 来自 promise 的等待函数
- json - 如何在 talend 中将 JSON 发送到 RestAPI?
- python - 在带有尾随零的列中写入 pandas 数据帧 to_csv
- c++ - Why doesn't connect() function see Slot?