gpt4 book ai didi

azure - 查询cosmosDB : get last element in array

转载 作者:行者123 更新时间:2023-12-02 03:34:38 35 4
gpt4 key购买 nike

我有这样的文档:

    { "id": ....,
"Title": ""title,
"ZipCodes": [
{
"Code": "code01",
"Name": "Name01"
},
{
"Code": "code02",
"Name": "Name02"
},
{
"Code": "code03",
"Name": "Name03"
} ],
"_rid": .......,
"_self": .......,
"_etag": ......,
"_attachments": "attachments/",
"_ts": ......

我被用来指挥

select c.id, c.ZipCodes[ARRAY_LENGTH (c.ZipCodes) -1] as ZipCodes from c

但是我收到错误,如何查询 cosmos DB 中的最后一个元素 ZipCodes。

最佳答案

您可以使用ARRAY_SLICE为了这。当传递 -1 时,它返回一个包含原始数组最后一个元素的数组。然后使用 [0] 对其进行索引以获取包含的单个元素(即邮政编码本身。)

SELECT c.id, 
ARRAY_SLICE(c.ZipCodes,-1)[0] AS LastZipCode
FROM c

关于azure - 查询cosmosDB : get last element in array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50632877/

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