How can I do this in sequelize?
SELECT ProductID, Name, ListPrice, ListPrice * 1.15 AS NewPrice
FROM Production
I've tried:
db.Production.findAndCountAll(
attributes: {
include: [
['ListPrice * 1.15', 'NewPrice']
]
}
).then(function(orders){
return res.jsonp(output);
})
But it doesn't work.
This is the query that I expect:
SELECT Production.ProductID, Production.Name, Production.ListPrice, Production.ListPrice * 1.15 AS NewPrice
FROM Production
Instead, I see this query:
SELECT Production.ProductID, Production.Name, Production.ListPrice, ListPrice * 1.15 AS NewPrice
FROM Production
You can use Sequelize.literal method. Here is the code:
db.Production.findAndCountAll(
attributes: [
[Sequelize.literal('ListPrice * 1.15'), 'NewPrice'],
]
).then(function(orders){
return res.jsonp(output);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With