javascript - How to Perform Arithmetic Operations in Sequelize? - Stack Overflow

How can I do this in sequelize?SELECT ProductID, Name, ListPrice, ListPrice * 1.15 AS NewPriceFROM P

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
Add a ment  | 

1 Answer 1

Reset to default 7

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);
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744397101a4572196.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信