2017-08-14 130 views
0

我已經保存在我的數據庫中的幾個文件,格式如下:選擇元素

{ 
    "text": "foo", 
    "items": [{ 
     "num": 1, 
     "value": 1.1 
    }, { 
     "num": 42, 
     "value": 3.14 
    }] 
} 

{ 
    "text": "bar", 
    "items": [{ 
     "num": 3, 
     "value": 5.0 
    }] 
} 

我想從每個文檔檢索「文本」和「價值」具有最高「num」的項目。所以在這個例子中,我的結果是:

{ 
    "text": "foo", 
    "value": 3.14 
} 

{ 
    "text": "bar", 
    "value": 5.0 
} 

有沒有什麼方法可以解決OrientDB的這個問題?

回答

1

我試着用這些記錄

enter image description here

,我用這個查詢

select rid,items.num as num,items.value as value from (
select @rid,items,$a[0].max as max from test 
let $a=(select max(items.num) as max from $parent.$current) 
unwind items 
) 
where items.num=max 

enter image description here

最好的問候, 亞歷山德羅

+0

謝謝,完美的作品! – monsul