Vic*_*nak 5 javascript mysql node.js sequelize.js
我怎样才能在续集中做到这一点?
SELECT ProductID, Name, ListPrice, ListPrice * 1.15 AS NewPrice
FROM Production
Run Code Online (Sandbox Code Playgroud)
我试过了:
db.Production.findAndCountAll(
attributes: {
include: [
['ListPrice * 1.15', 'NewPrice']
]
}
).then(function(orders){
return res.jsonp(output);
})
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
这是我期望的查询:
SELECT Production.ProductID, Production.Name, Production.ListPrice, Production.ListPrice * 1.15 AS NewPrice
FROM Production
Run Code Online (Sandbox Code Playgroud)
相反,我看到了这个查询:
SELECT Production.ProductID, Production.Name, Production.ListPrice, ListPrice * 1.15 AS NewPrice
FROM Production
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以使用Sequelize.literal方法。这是代码:
db.Production.findAndCountAll(
attributes: [
[Sequelize.literal('ListPrice * 1.15'), 'NewPrice'],
]
).then(function(orders){
return res.jsonp(output);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2267 次 |
| 最近记录: |