[英]How to Filter and Sort array of object within array of object in ArangoDB
[英]Filter within array in arangodb not working
Q20.寫一個 MongoDB 查詢來查找那些得分不超過 10 的餐廳的餐廳 ID、名稱、自治市鎮和美食。
我正在嘗試以下方式,但我可以看到我得到的餐館結果得分為 [2,6,10,9,14] 和 [8,23,12,12]。 所以我知道這不可能。
for r in restaraunts
for g in r.grades
filter g.score <=10
return distinct {ID:r.restaurant_id,name:r.name,borough:r.borough,cuisine:r.cuisine,score:r.grades[*].score}
請幫忙,我嘗試過不同的分數預測,但我覺得我忽略了一些東西。 如果我使用 collect 我仍然會出錯
collect rest=r.restaurant_id,name= r.name, bor=r.borough,cuis=r.cuisine, sc=r.grades[*].score into groups
for g in sc
filter g<=10
return {rest:rest,name:name,bor:bor,cuis:cuis,sc:g}
使用MAX()
function 確定要過濾的值:
for r in restaurants
LET score = MAX(r.grades[*].score)
filter score <=10
return distinct {ID:r.restaurant_id,name:r.name,borough:r.borough,cuisine:r.cuisine,score:score}
我沒有針對您的數據集進行測試,但是使用了這個小片段:
LET r = {'grades': [ {score: 5}, {score: 7}, {score: 15} ] }
RETURN MAX(r.grades[*].score)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.