通过行正值量与sequ elize.js排序
可以有不同的类型(布尔,时间戳),他们会参加排序多个列。
排序:在多个列与正值行中,上级此行应该是结果
例:
表:
0, “text”, true, ‘ ‘2019-02-04 12:35:17.655+02’’
0, “text”, false, null
2, “text”, true, ‘ ‘2019-02-04 12:35:17.655+02’’
0, null, false, null
0, “text”, true, null
结果:
2, “text”, true, ‘ ‘2019-02-04 12:35:17.655+02’’
0, “text”, true, ‘ ‘2019-02-04 12:35:17.655+02’’
0, “text”, true, null
0, “text”, false, null
0, null, false, null
我认为,我们需要以某种方式计数每一行的列中的正值,然后由该值排序。究竟写这与sequelize.js请求或者Postgres的我不知道。
请你帮助我好吗 ?
回答如下:您可以使用order
属性在查询基于一个关键结果进行排序。例如
Products.findAll({
where: { isSoldOut: false },
// Sort products by prices in descending order
// Most expensive (highest values) first
order: [
['price', 'DESC']
],
attributes: ['id', 'name', 'price', 'image']
});