gpt4 book ai didi

sql - 在 Microsoft 流分析查询中选择 JSON 数组中的第一个元素

转载 作者:行者123 更新时间:2023-12-05 00:56:56 25 4
gpt4 key购买 nike

所以我遇到了一些问题。我从外部 API 检索一些天气数据。它以 JSON 形式返回并发送到 Azure IoT 中心。流分析将 json 处理为正确的格式,但我在这里遇到了问题。

元素:Current_Condition,为数组格式。它始终在 [0] 位置上有一个元素。我只需要从第一个位置获取该数组的数据,无需过滤 id 等内容。

下面是完整的数据

{
"deviceId": "aNewDevice",
"data": {
"data": {
"current_condition": [
{
"cloudcover": "0",
"FeelsLikeC": "0",
"FeelsLikeF": "32",
"humidity": "100",
"observation_time": "10:00 AM",
"precipMM": "0.0",
"pressure": "1020",
"temp_C": "2",
"temp_F": "36",
"visibility": "0",
"weatherCode": "143",
"weatherDesc": [ { "value": "Fog, Mist" } ],
"weatherIconUrl": [ { "value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0006_mist.png" } ],
"winddir16Point": "SSW",
"winddirDegree": "210",
"windspeedKmph": "7",
"windspeedMiles": "4"
}
],
"request": [
{
"query": "Nijmegen, Netherlands",
"type": "City"
}
]
}
}
}

另外,对我到底需要做什么进行一些解释(不仅仅是示例或代码答案)对将来也很有好处。 (请求元素毕竟也有同样的问题。)

提前致谢:)

最佳答案

您需要使用GetArrayElement功能。例如:

SELECT GetRecordProperty(GetArrayElement(Current_Condition, 0), 'humidity')

为了让它更好一点,您可以将查询分为两个步骤:

WITH CurrentConditions AS
(
SELECT deviceId, GetArrayElement(Current_Condition, 0) as conditions
FROM input
)

SELECT deviceID, conditions.humidity
FROM CurrentConditions

关于sql - 在 Microsoft 流分析查询中选择 JSON 数组中的第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35503674/

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