How do I multiply the result value in Knex
db.select().table('sales')
.whereBetween('date-s', [req.params.startDate,req.params.endDate])
.sum({totalSales:"sales-after-returns"})
.avg({averageSales:"sales-after-returns"})
.sum({sixtyPercentOfTotalSale:"sales-after-returns"} * 0.6)
.then(result => res.json(result))
})
the first two line is working fine ,I am not getting the third value sixtyPercentOfTotalSale ,how can I alter the sum of column ?
this is the error I'm getting in the console
Unhandled rejection TypeError: value.toLowerCase is not a function
Not sure about the problem but this might work-- Just use knex.raw-
db.select().table('sales')
.whereBetween('date-s', [req.params.startDate,req.params.endDate])
.columns([
knex.raw('sum(sales-after-returns) as totalSales'),
knex.raw('avg(sales-after-returns) as averageSales'),
knex.raw('sum(sales-after-returns * 0.6) as sixtyPercentOfTotalSale'),
])
.then(result => res.json(result))
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.