postgresql 按包含日期的属性排序

ctehm74n  于 2023-04-05  发布在  PostgreSQL
关注(0)|答案(1)|浏览(109)

我有一个大约有20个顶点和60条边的图。顶点有两个标签:一个标记为Person,另一个标记为Merchant。它们之间的边表示交易,它将其状态和交易日期存储为“mm/dd/yyyy”(月/日/年)。我想按降序检索每个交易的日期,但当我查询它时,它不按降序显示日期:

SELECT * FROM cypher('FraudDetection', $$
        MATCH (victim :Person)-[r :HAS_BOUGHT_AT]->(merchant)
        WHERE r.status = "Disputed"
        RETURN victim.name, merchant.name, r.amount, r.time ORDER BY r.time DESC
$$) AS (Customer agtype, Store agtype, Amount agtype, Transaction_Time agtype);

 customer  |       store        | amount | transaction_time 
-----------+--------------------+--------+------------------
 "Olivia"  | "RadioShack"       | "1884" | "8/1/2014"
 "Olivia"  | "Urban Outfitters" | "1152" | "8/10/2014"
 "Madison" | "Apple Store"      | "1925" | "7/18/2014"
 "Olivia"  | "Apple Store"      | "1149" | "7/18/2014"
 "Marc"    | "Apple Store"      | "1914" | "7/18/2014"
 "Paul"    | "Apple Store"      | "1021" | "7/18/2014"
 "Madison" | "RadioShack"       | "1368" | "7/1/2014"
 "Madison" | "Urban Outfitters" | "1374" | "7/10/2014"
 "Marc"    | "Urban Outfitters" | "1424" | "5/10/2014"
 "Paul"    | "Urban Outfitters" | "1732" | "5/10/2014"
 "Paul"    | "RadioShack"       | "1415" | "4/1/2014"
 "Marc"    | "RadioShack"       | "1721" | "4/1/2014"
 "Madison" | "Macys"            | "1816" | "12/20/2014"
 "Olivia"  | "Macys"            | "1790" | "12/20/2014"
 "Marc"    | "Macys"            | "1003" | "12/20/2014"
 "Paul"    | "Macys"            | "1849" | "12/20/2014"
(16 rows)

-- The month of December is the last to appear...

按降序检索数据的正确方法是什么?

whlutmcx

whlutmcx1#

AGE Cypher似乎没有datetime数据类型,即使it exists in neo4j也是如此。与其将日期存储为字符串,不如将它们Map到一个小型自定义版本的datetime,以进行算术比较。由于您只存储日,月和年,因此这应该是可行的。

相关问题