简体   繁体   中英

In orientdb how to select any 5 rows from set of data

My database class is having 1000 rows out of which i want when i fire query it should give me any arbitrary 5 rows on each hit, can or can not be unique.

What i need to add in query for same?

You can use this simple JavaScript function which will take all records from v and return 5 random:

var g=orient.getDatabase(); 
var b=g.query("select from v");
var result = [];
for(i=1;i<=5;i++){
   item=b[Math.floor(Math.random()*b.length)]
   result.push(item);
}
return result;

Than you can query for results using:

select expand(result) from (select randomFunc() as result)

See screenshots from Studio:

在此输入图像描述 在此输入图像描述

Hope it will help you.

No, currently there isn't a random function. You could see this link .

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM