最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

通过行正值量与sequ elize.js排序

IT培训 admin 6浏览 0评论

通过行正值量与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

我认为,我们需要以某种方式计数每一行的列中的正值,然后由该值排序。究竟写这与sequ​​elize.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']
 });

通过行正值量与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

我认为,我们需要以某种方式计数每一行的列中的正值,然后由该值排序。究竟写这与sequ​​elize.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']
 });

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论