目的是通过custmer_id显示最近的交易

时间:2019-06-14 19:50:16

标签: postgresql greatest-n-per-group

我的代码按计划按行号排列最近的客户交易,但是我无法过滤联接以显示在每个客户的最后一笔交易上。目的是显示每个customer_id的最新详细客户交易。我试图使用window函数,然后过滤结果列。

yourproject-logic

1 个答案:

答案 0 :(得分:0)

您可以使用DISTINCT ON解决此问题:

[
    {
        "pointerToViolation": "#/middleware/1",
        "causingExceptions": [
            {
                "schemaLocation": "#/definitions/weblogic",
                "pointerToViolation": "#/middleware/1",
                "causingExceptions": [
                    {
                        "schemaLocation": "#/definitions/weblogic/properties/buildInfo",
                        "pointerToViolation": "#/middleware/1/buildInfo",
                        "causingExceptions": [],
                        "keyword": "required",
                        "message": "required key [adminSslPort] not found"
                    },
                    {
                        "schemaLocation": "#/definitions/weblogic/properties/type",
                        "pointerToViolation": "#/middleware/1/type",
                        "causingExceptions": [],
                        "keyword": "const",
                        "message": ""
                    }
                ],
                "message": "2 schema violations found"
            },
            {
                "schemaLocation": "#/definitions/tomcat/properties/buildInfo",
                "pointerToViolation": "#/middleware/1/buildInfo",
                "causingExceptions": [],
                "keyword": "required",
                "message": "required key [classpath] not found"
            }
        ],
        "keyword": "oneOf",
        "message": "#: 0 subschemas matched instead of one"
    }
]
type

如果您不想看到没有购物的客户,可以将LEFT JOIN更改为JOINS。