Azure cosmosdb DocumentDB-如何在查询的选择部分返回距离?

Azure cosmosdb DocumentDB-如何在查询的选择部分返回距离?,azure-cosmosdb,Azure Cosmosdb,我想返回我的搜索坐标和我要搜索的字段之间的距离 例如,您可以使用以下查询: 他们使用以下示例查询: -- Find all volcanoes of type Stratovolcano -- (http://www.sciencedaily.com/terms/stratovolcano.htm) -- that are within 100 km of Redmond, WA. SELECT * FROM volcanoes v WHERE ST_DISTANCE(v.Location

我想返回我的搜索坐标和我要搜索的字段之间的距离

例如,您可以使用以下查询:

他们使用以下示例查询:

-- Find all volcanoes of type Stratovolcano
-- (http://www.sciencedaily.com/terms/stratovolcano.htm) 
-- that are within 100 km of Redmond, WA. 
SELECT *
FROM volcanoes v
WHERE ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) < 100 * 1000
AND v.Type = "Stratovolcano"
AND v["Last Known Eruption"] = "Last known eruption from 1800-1899, inclusive"
假设我想把位于[-121.758,46.87]的火山和搜索坐标[-122.19,47.36]之间的距离用米表示

我的T-SQL开发人员说,我可以从WHERE子句中获取整个ST_距离位,并将其与SELECT一起包含,如下所示:

-- Find all volcanoes of type Stratovolcano
-- (http://www.sciencedaily.com/terms/stratovolcano.htm) 
-- that are within 100 km of Redmond, WA. 
SELECT *, ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    })
FROM volcanoes v
WHERE ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) < 100 * 1000
AND v.Type = "Stratovolcano"
AND v["Last Known Eruption"] = "Last known eruption from 1800-1899, inclusive"
我尝试了很多方法,比如v.*,将ST_DISTANCE的结果与AS混淆,但我没有取得任何进展,也没有在Google中找到我需要的东西

那么我需要做什么呢?对我来说,在一定距离内进行查询是至关重要的,但如果我必须在客户端重新计算所有这些距离,那么它的用处有限。

查询必须使用SELECT v,ST_distance。。。代替SELECT*,ST_距离。。。。与ANSI-SQL类似,DocumentDB中的SELECT子句可以包含值列表,也可以使用*,但不能同时使用两者

完整查询:

-- Find all volcanoes of type Stratovolcano
-- (http://www.sciencedaily.com/terms/stratovolcano.htm) 
-- that are within 100 km of Redmond, WA. 
SELECT v, ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) AS DistanceMetres
FROM volcanoes v
WHERE ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) < 100 * 1000
AND v.Type = "Stratovolcano"
AND v["Last Known Eruption"] = "Last known eruption from 1800-1899, inclusive"
查询必须使用SELECT v,ST_距离。。。代替SELECT*,ST_距离。。。。与ANSI-SQL类似,DocumentDB中的SELECT子句可以包含值列表,也可以使用*,但不能同时使用两者

完整查询:

-- Find all volcanoes of type Stratovolcano
-- (http://www.sciencedaily.com/terms/stratovolcano.htm) 
-- that are within 100 km of Redmond, WA. 
SELECT v, ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) AS DistanceMetres
FROM volcanoes v
WHERE ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) < 100 * 1000
AND v.Type = "Stratovolcano"
AND v["Last Known Eruption"] = "Last known eruption from 1800-1899, inclusive"

我编辑了你的答案来解释为什么*不同。你能把它标记为答案吗?我编辑了你的答案来解释为什么*不同。你能把它标为答案吗?
-- Find all volcanoes of type Stratovolcano
-- (http://www.sciencedaily.com/terms/stratovolcano.htm) 
-- that are within 100 km of Redmond, WA. 
SELECT v, ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) AS DistanceMetres
FROM volcanoes v
WHERE ST_DISTANCE(v.Location, { 
    "type": "Point", 
    "coordinates": [-122.19, 47.36] 
    }) < 100 * 1000
AND v.Type = "Stratovolcano"
AND v["Last Known Eruption"] = "Last known eruption from 1800-1899, inclusive"