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
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
Share
Improve this question
asked Aug 20, 2016 at 1:22
VicheanakVicheanak
6,70420 gold badges67 silver badges99 bronze badges
2
- Any progress on this? – Airton Gessner Commented Oct 14, 2016 at 13:41
- yeah bro. already hand that project to my client. I end up, wrote a raw query for that one. I'm wondering if I do this might work: ['Production.ListPrice * 1.15', 'NewPrice']. You can try as now i'm busy on another project. – Vicheanak Commented Oct 14, 2016 at 13:45
1 Answer
Reset to default 7You 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);
})
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744397101a4572196.html
评论列表(0条)