gpt4 book ai didi

python - 根据 Cosmos DB 数组中的最小日期按顺序返回结果

转载 作者:行者123 更新时间:2023-12-03 07:02:58 26 4
gpt4 key购买 nike

我目前将数据存储在 cosmosdb 中,可以像这样获取

选择 t.code、t.从 t 出发

返回结果如下

    {
"code": "BAHVB2",
"departures": [
{
"code": "14601",
"startDate": "2022-09-13T00:00:00",
"endDate": "2022-09-20T00:00:00",
"available": true,
"definite": false,

},
{
"code": "14602",
"startDate": "2022-09-27T00:00:00",
"endDate": "2022-10-04T00:00:00",
"available": true,
"definite": false,

},
{
"code": "14603",
"startDate": "2022-12-10T00:00:00",
"endDate": "2022-12-17T00:00:00",
"available": true,
"definite": false,

}
]
},
{
"code": "BBFLL2",
"departures": [
{
"code": "14618",
"startDate": "2022-08-30T00:00:00",
"endDate": "2022-09-04T00:00:00",
"available": true,
"definite": false,

},
{
"code": "14619",
"startDate": "2022-09-09T00:00:00",
"endDate": "2022-09-14T00:00:00",
"available": true,
"definite": false,

},
{
"code": "14620",
"startDate": "2022-09-19T00:00:00",
"endDate": "2022-09-24T00:00:00",
"available": true,
"definite": false,

},
{
"code": "14622",
"startDate": "2022-10-11T00:00:00",
"endDate": "2022-10-16T00:00:00",
"available": true,
"definite": false,

},
{
"code": "14623",
"startDate": "2022-11-07T00:00:00",
"endDate": "2022-11-12T00:00:00",
"available": true,
"definite": false,
}
]
},
]

如何创建一个查询来根据第一个/最小开始日期对结果进行排序?

如代码所示:BAHVB2 的最小值为 2022-09-13,BBFLL2 的最小值为 2022-08-30,所以 BBFFL2 应该首先出现?

是否有一个好的方法来执行 where 子句?我正处于十字路口,因为到目前为止我看到的所有指南都没有那么解释性

最佳答案

像这样的东西应该可以完成工作

SELECT t.code, t.departures 
FROM t
ORDER BY MIN(ARRAY(SELECT d.startDate FROM d IN t.departures))

关于python - 根据 Cosmos DB 数组中的最小日期按顺序返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72013309/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com